﻿using DevExpress.XtraEditors.Repository;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.Model;
using HuaCheng.SendAndReceive;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Xml;
using HuaCheng.Controller;
using System.Drawing;
using DevExpress.XtraTreeList;
using HuaCheng.DataAccess;
using HuaCheng.CommonClass;
using System.Data;
using DevExpress.XtraEditors;
using System.Text.RegularExpressions;

namespace HuaCheng.Views
{
    /// <summary>
    /// 工步设置
    /// </summary>
    public partial class StepSet : Form
    {
        //打开xml文件的工步信息对象
        StepSetInfo ssiObtain = new StepSetInfo();
        //要继承上一工步保护条件的当前工步
        TreeListNode inheritNode = new TreeListNode();
        //判断标准/专业工步
        public static bool isStandard=true;
        //用于存储当前定制的单位对应的物理量
        List<string> unitTypeSet = new List<string>();
        //用于保存被复制节点的信息
        StepInfo copyLimit;
        //用于保存被复制节点的子节点的信息
        StepInfo copyChildLimit;
        List<StepInfo> copyChildLimitSet=new List<StepInfo>();
        TreeListNode countCopyNode = null;
        //判断是否点击过复制标志位
        bool copyFlag = false;
        //判断此次工步设置是新增的还是读取xml的，用于恢复时选择恢复到哪个状态
        bool openXmlFlag = false;
        //右键菜单被触发的节点
        TreeListNode currentNode = null;
        public List<Channel> batteryIE = new List<Channel>();
        //“如果”操作符下拉菜单项
        public string[] ComboxJumpOperatorItem = { ">", ">=", "=", "<", "<=" };
        //“如果”跳转下拉菜单
        RepositoryItemComboBox ComboxJumpTo = new RepositoryItemComboBox();
        //专业工步“如果”跳转下拉菜单
        RepositoryItemComboBox ComboxProJumpTo = new RepositoryItemComboBox();
        //“如果”条件下拉菜单
        RepositoryItemComboBox ComboxJumpCond = new RepositoryItemComboBox();
        //时间编辑控件
        RepositoryItemTimeSpanEdit TimeSpanEdit = new RepositoryItemTimeSpanEdit();
        //“工步名称”下拉菜单
        RepositoryItemComboBox ComboxStepName = new RepositoryItemComboBox();
        //“如果”操作符下拉菜单
        RepositoryItemComboBox ComboxOperator = new RepositoryItemComboBox();
        RepositoryItemComboBox ComboxRecordCond = new RepositoryItemComboBox();
        //“脉冲工况”，“斜坡工况”
        RepositoryItem openDialog = new RepositoryItemTextEdit();
        //不会获得焦点的格子
        RepositoryItem TextNull = new RepositoryItem();
        //自动生成内容的格子
        RepositoryItem TextNoEdit = new RepositoryItemTextEdit();
        //允许编辑的格子
        RepositoryItem TextEdit = new RepositoryItemTextEdit();
        //必须编辑的格子
        RepositoryItem TextNeedEdit = new RepositoryItemTextEdit();
        //从数据库读出的上次工步
        List<StepInfo> loadStepList = new List<StepInfo>();
        //在编辑时存储数据
        string cellValue;
        //socket服务
        public Socket server;
        //实际通道号
        int realId;
        //柜号
        int gid;
        //中位机号
        int mid;
        //通道号
        int cid;
        ////标准、专业工步标志
        //public static bool stepFlag = true;
        //并联通道组
        List<int> chlIdList;
        //设备号
        public static string devIp;
        //存储整个工步编辑界面的信息
        public StepSetInfo sp;
        //判断界面关闭是否由启动按钮触发
        public bool Result;
        public Dictionary<string, Color> nodeColor = new Dictionary<string, Color>();
        public delegate void BeforeStart(Channel chls);
        //全局参数接收前台传过来的通道信息
        public List<Channel> chlList;
        bool tLStepEditorFlag = false;//判断工步表是否允许编辑
        public static Dictionary<int, string> copyChls;
        public string queryType;
        //起始工步号
        public static int startId;

        #region 初始化方法
        /// <summary>
        /// 初始化方法
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="cid"></param>
        /// <param name="realId"></param>
        /// <param name="ip"></param>
        /// <param name="chlList"></param>
        /// <param name="chl"></param>
        /// <param name="qType"></param>
        public StepSet(int realId, string ip, List<int> chlIdList, List<Channel> chls, string qType)
        {
            Result = false;
            InitializeComponent();
            //初始化各下拉框
            InitializeComboboxAndCell();
            this.realId = realId;//实际id
            this.mid = chls[realId].Mid;//中位机号
            this.cid = chls[realId].Cid;//映射通道号
            this.gid = chls[realId].Gid;//柜号
            this.chlIdList = chlIdList;//并联列表
            chlList = chls;
            devIp = ip;//设备IP
            //初始化工步
            LoadStepInfo(devIp, gid, mid, cid);
            StepColor sc = new StepColor();
            nodeColor = sc.GetStepColor();
            SetCustom();
            SetTreeListUnit();            
            Reload_StepSet();
            copyChls = new Dictionary<int, string>();
            queryType = qType;
            if (queryType == "复制工步")//如果是复制工步操作
            {
                this.btnSelectChl.Visible = true;//显示按钮
                this.tLStepEditor.OptionsBehavior.Editable = false;//表格不可编辑
                this.tlProfessionStep.OptionsBehavior.Editable = false;//不可编辑
                SetFuncState(false);//保护条件不可编辑
                SetProFuncState(false);//保护条件不可编辑
                this.cmsProNode = null;//右键菜单不允许打开
                this.cmsNode = null;//右键菜单不允许打开
            }
            if (queryType == "重置工步")
            {
                if (isStandard)
                {
                    this.tabPageUniqueStep.Parent = null;
                }
                else
                {
                    this.tabPageStandStep.Parent = null;
                }
            }
        }
        /// <summary>
        /// 初始化方法2
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="cid"></param>
        /// <param name="realId"></param>
        /// <param name="ip"></param>
        /// <param name="chlList"></param>
        /// <param name="chl"></param>
        /// <param name="qType"></param>
        public StepSet()
        {
            Result = false;
            InitializeComponent();
            //初始化各下拉框
            InitializeComboboxAndCell();
            //初始化工步
            //LoadStepInfo(devIp, gid, mid, cid);
            StepColor sc = new StepColor();
            nodeColor = sc.GetStepColor();
            SetCustom();
            SetTreeListUnit();

            this.Text = ResourceCulture.GetString("StartTitleText");
            copyChls = new Dictionary<int, string>();
        }

        public void updateStepSet(int realId, string ip, List<int> chlIdList, List<Channel> chls, string qType)
        {
            Result = false;
            this.realId = realId;//实际id
            this.mid = chls[realId].Mid;//中位机号
            this.cid = chls[realId].Cid;//映射通道号
            this.gid = chls[realId].Gid;//柜号
            this.chlIdList = chlIdList;//并联列表
            chlList = chls;
            devIp = ip;//设备IP
            //初始化工步
            LoadStepInfo(devIp, gid, mid, cid);
            Reload_StepSet();
            queryType = qType;
            if (queryType == "复制工步")//如果是复制工步操作
            {
                this.btnSelectChl.Visible = true;//显示按钮
                this.tLStepEditor.OptionsBehavior.Editable = false;//表格不可编辑
                this.tlProfessionStep.OptionsBehavior.Editable = false;//不可编辑
                SetFuncState(false);//保护条件不可编辑
                SetProFuncState(false);//保护条件不可编辑
                this.cmsProNode.Enabled = false;//右键菜单不允许打开
                this.cmsNode.Enabled = false;//右键菜单不允许打开
            }
            else if (queryType == null ||queryType=="整柜启动")
            {
                this.btnSelectChl.Visible = false;//不显示按钮
                this.tLStepEditor.OptionsBehavior.Editable = true;//表格可编辑
                this.tlProfessionStep.OptionsBehavior.Editable = true;//可编辑
                SetFuncState(true);//保护条件可编辑
                SetProFuncState(true);//保护条件可编辑
                this.cmsProNode.Enabled = true;//右键菜单允许打开
                this.cmsNode.Enabled = true;//右键菜单允许打开
            }
            else if (queryType == "重置工步")
            {
                if (isStandard)
                {
                    this.tabPageUniqueStep.Parent = null;
                }
                else
                {
                    this.tabPageStandStep.Parent = null;
                }
            }
        }
        #endregion
        #region 工步编辑表的属性和事件
        /// <summary>
        /// 根据工步表初始化工步内容
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="cid"></param>
        /// <param name="devID"></param>
        private void LoadStepInfo(string ip, int gid, int mid,int cid)
        {
            //如果工步表中不存在该通道的工步记录，treeList新增一个节点
            if (StepHelper.GetTestIdById(ip, gid, mid,cid) == "0")
            {
                //新建标准工步节点
                TreeListNode tmpNode = tLStepEditor.Nodes.Add();
                tmpNode["StepNum"] = tLStepEditor.Nodes.Count;
                tLStepEditor.FocusedNode = tmpNode;
                ComboxJumpTo.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
                //新建专业工步节点
                TreeListNode tmpProNode = tlProfessionStep.Nodes.Add();
                tmpProNode["StepNum"] = tlProfessionStep.Nodes.Count;
                tlProfessionStep.FocusedNode = tmpProNode;
                ComboxProJumpTo.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
            }
            //如果工步表中有该通道的工步记录，读取工步记录显示出来
            else
            {
                TreeList treeList;
                RepositoryItemComboBox rItemCbx;
                //非DCIR测试
                if (StepHelper.GetDcirFlagById(ip, gid, mid, cid) == false)
                {
                    //标准工步
                    if (StepHelper.GetStepFlagById(ip, gid, mid, cid) == true)
                    {
                        isStandard = true;
                        treeList = tLStepEditor;
                        //下拉框
                        rItemCbx = ComboxJumpTo;
                        //新建专业工步节点
                        if (tlProfessionStep.Nodes.Count != 1)
                        {                      
                            TreeListNode tmpProNode = tlProfessionStep.Nodes.Add();
                            tmpProNode["StepNum"] = tlProfessionStep.Nodes.Count;
                            ComboxProJumpTo.Items.Add("goto:" + Convert.ToString(tmpProNode["StepNum"]));
                            tlProfessionStep.FocusedNode = tmpProNode;
                        }
                    }
                    else
                    {
                        isStandard = false;
                        treeList = tlProfessionStep;
                        rItemCbx = ComboxProJumpTo;
                        //新建标准工步节点
                        if (tLStepEditor.Nodes.Count != 1)
                        {
                            TreeListNode tmpNode = tLStepEditor.Nodes.Add();
                            tmpNode["StepNum"] = tLStepEditor.Nodes.Count;
                            ComboxJumpTo.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
                            tLStepEditor.FocusedNode = tmpNode;
                        }
                    }
                    loadStepList = new List<StepInfo>();
                    //从表中读取工步数据
                    List<byte[]> byteList = StepHelper.GetBinaryListById("0", devIp, gid, mid, cid);
                    //将工步数据恢复成StepInfo对象
                    for (int i = 0; i < byteList.Count; i++)
                    {
                        //将字节数组反序列化StepInfo对象
                        StepInfo stepInfo = (StepInfo)SerializableControl.DeserializeWithBinary(byteList[i]);
                        loadStepList.Add(stepInfo);
                        rItemCbx.Items.Add("goto:" + Convert.ToString(i + 1));
                    }
                    //将工步list转为当前单位的数值
                    List<StepInfo> currentList = DataControl.DataConvertToCurrent(loadStepList);
                    treeList = StepControl.SetTreeListByStepList(currentList, treeList);
                    ReconstructionStepNum();//重建序号
                    //参数设置
                    SetProctParameter(loadStepList[0].ProtSelect, loadStepList[0].ProtCondition);
                    if (isStandard == true)
                    {
                        tabControlAll.SelectedIndex = 0;
                        //标准工步的基本信息
                        if (loadStepList[0].StartStep == 0)
                        {
                            //起始工步
                            nudStartStep.Value = 1;
                        }
                        else
                        {
                            //起始工步
                            nudStartStep.Value = loadStepList[0].StartStep;
                        }
                        //创建者
                        txtName.Text = loadStepList[0].Creator;
                        //电池批号
                        txtNo.Text = loadStepList[0].BatteryNum;
                        //备注
                        txtRemark.Text = loadStepList[0].Remark;
                    }
                    else if (isStandard == false)
                    {
                        tabControlAll.SelectedIndex = 1;
                        //专业工步的基本信息
                        if (loadStepList[0].StartStep == 0)
                        {
                            //起始工步
                            nudBeginStep.Value = 1;
                        }
                        else
                        {
                            //起始工步
                            nudBeginStep.Value = loadStepList[0].StartStep;
                        }
                        //创建者
                        txtCreator.Text = loadStepList[0].Creator;
                        //电池批号
                        txtBatteryNum.Text = loadStepList[0].BatteryNum;
                        //备注
                        txtRemarks.Text = loadStepList[0].Remark;
                    }
                }
                else
                {
                    //新建标准工步节点
                    TreeListNode tmpNode = tLStepEditor.Nodes.Add();
                    tmpNode["StepNum"] = tLStepEditor.Nodes.Count;
                    tLStepEditor.FocusedNode = tmpNode;
                    ComboxJumpTo.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
                    //新建专业工步节点
                    TreeListNode tmpProNode = tlProfessionStep.Nodes.Add();
                    tmpProNode["StepNum"] = tlProfessionStep.Nodes.Count;
                    tlProfessionStep.FocusedNode = tmpProNode;
                    ComboxProJumpTo.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
                }
            }
        }
        /// <summary>
        /// 斜坡工况，脉冲工况弹窗事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void openDialog_DoubleClick(object sender, EventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }

            TreeListNode tmpNode = treeList.FocusedNode;
            string mode="电流";//默认模式
            float magnification = 1.0f;//默认倍率
            string path = "";//路径
            string timeUnit = "s";//时间单位
            string curOrPowUnit = "A";//电流/功率单位
            DataTable dt = new DataTable();//默认工况表
            if (tmpNode["Cap"] != null)//模式
            {
                string strmode = Convert.ToString(tmpNode["Cap"]);
                mode = strmode.Substring(3, strmode.Length - 3);
            }
            if (tmpNode["Energy"] != null)//倍率
            {
                string strmagni = Convert.ToString(tmpNode["Energy"]);
                magnification = Convert.ToSingle(strmagni.Substring(3, strmagni.Length - 3));
            }
            if (tmpNode["Current"] != null)//json数据
            {
                dt = Collection.ToDataTable(Convert.ToString(tmpNode["Current"]));
            }
            if (tmpNode["DeltaVolt"]!=null)//路径
            {
                string strpath = Convert.ToString(tmpNode["DeltaVolt"]);
                path = Convert.ToString(strpath.Substring(3, strpath.Length - 3));
            }
            if (tmpNode["Power"] != null)//电流/功率单位
            {
                string curpow = Convert.ToString(tmpNode["Power"]);
                curOrPowUnit = curpow.Substring(8);
            }
            if (tmpNode["LoadResistor"] != null)//时间单位
            {
                string time = Convert.ToString(tmpNode["LoadResistor"]);
                timeUnit = time.Substring(5);
            }
            if (Convert.ToString(tmpNode["StepName"]) == "斜坡工况")
            {                
                SlopeCondition slopeCondition = new SlopeCondition(dt,mode,magnification,path,curOrPowUnit,timeUnit);
                slopeCondition.GetBackSlopParams += new SlopeCondition.GetSlopeParams(GetCondicTab);
                slopeCondition.Owner = this;
                slopeCondition.StartPosition = FormStartPosition.CenterScreen;
                slopeCondition.ShowDialog();
            }
            else if (Convert.ToString(tmpNode["StepName"]) == "脉冲工况")
            {
                PulseCondition pulseCondition = new PulseCondition(dt,mode,magnification,path,curOrPowUnit,timeUnit);
                pulseCondition.GetBackPulseParams += new PulseCondition.GetPulseParams(GetCondicTab);
                pulseCondition.Owner = this;
                pulseCondition.StartPosition = FormStartPosition.CenterScreen;
                pulseCondition.ShowDialog();
            }
        }
        /// <summary>
        /// 工况信息显示在treelist中
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="rate"></param>
        /// <param name="mode"></param>
        public void GetCondicTab(DataTable dt,float rate,string mode,string path,string curOrPowUnit,string timeUnit)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            treeList.FocusedNode["Voltage"] = "工况数据：";
            treeList.FocusedNode["Current"] = Collection.ToJson(dt);//把工况表转成json赋给单元格
            treeList.FocusedNode["Cap"] = "模式:" + mode;//模式
            treeList.FocusedNode["Energy"] = "倍率:" + rate;//倍率
            treeList.FocusedNode["DeltaVolt"] = "路径:" + path;
            treeList.FocusedNode["Power"] = "电流/功率单位:" + curOrPowUnit;//电流、功率单位
            treeList.FocusedNode["LoadResistor"] = "时间单位:" + timeUnit;//时间单位
        }
        /// <summary>
        /// 设置各下拉菜单,单元格的属性和事件
        /// </summary>
        private void InitializeComboboxAndCell()
        {
            TimeSpanEdit.AllowEditMilliseconds = true;
            TimeSpanEdit.AllowEditDays = false;

            ComboxOperator.Items.AddRange(ComboxJumpOperatorItem);
            ComboxOperator.NullText = ">";
            //从字典表读取工步名称
            List<string> ComboxStepNameItem = DicHelper.RetrieveAllStepName();
            //“结束”工步不在下拉框内，需移除
            ComboxStepNameItem.RemoveAt(ComboxStepNameItem.Count - 1);
            ComboxStepName.Items.AddRange(ComboxStepNameItem);
            //从字典表读取记录条件
            List<string> ComboxRecordCondItem = DicHelper.RetrieveRecordCond();
            ComboxRecordCond.Items.AddRange(ComboxRecordCondItem);
            ComboxRecordCond.NullText = "时间段";
            //从字典表读取跳转条件
            List<string> ComboxJumpCondItem = DicHelper.RetrieveJumpCond();
            ComboxJumpCond.Items.AddRange(ComboxJumpCondItem);
            ComboxJumpCond.NullText = "电压";
            //从字典表读取跳转目标
            List<string> ComboxJumpToItem = DicHelper.RetrieveJumpTo();
            ComboxJumpTo.Items.AddRange(ComboxJumpToItem);
            ComboxJumpTo.NullText = "goto:完成";
            //从字典表读取跳转目标专业工步
            List<string> ComboxProJumpToItem = DicHelper.RetrieveJumpTo();
            ComboxProJumpTo.Items.AddRange(ComboxProJumpToItem);
            ComboxProJumpTo.NullText = "goto:完成";
            ComboxStepName.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ComboxJumpCond.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ComboxOperator.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ComboxJumpTo.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ComboxProJumpTo.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            ComboxRecordCond.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
            //给不同类型的单元格设置属性和事件
            openDialog.DoubleClick += openDialog_DoubleClick;
            openDialog.ReadOnly = true;
            TextNull.ReadOnly = true;
            TextNoEdit.ReadOnly = true;
            TextNoEdit.MouseDown += tLStepEditor_MouseDown;
            TextNeedEdit.Leave += NeedEdit_Leave;
            TextNeedEdit.KeyPress += CellEdit_KeyPress;
            TextNeedEdit.Leave += CellEdit_Leave;
            TextNeedEdit.MouseDown += tLStepEditor_MouseDown;
            TextEdit.KeyPress += CellEdit_KeyPress;
            TextEdit.Leave += CellEdit_Leave;
            TextEdit.MouseDown += tLStepEditor_MouseDown;
            TimeSpanEdit.MouseDown += tLStepEditor_MouseDown;
            TimeSpanEdit.Leave += TimeSpan_Leave;
        }
        /// <summary>
        /// 显示每一行的颜色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLStepEditor_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)
        {
            foreach (string key in nodeColor.Keys)
            {
                if (object.Equals(e.Node["StepName"], key))
                {
                    e.Appearance.BackColor = nodeColor[key];
                }
            }
        }
        /// <summary>
        /// 重新排列工步号
        /// </summary>
        private void ReconstructionStepNum()
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            for (int i = 0; i < treeList.Nodes.Count; i++)
            {
                treeList.Nodes[i]["StepNum"] = i + 1;
            }
        }
        /// <summary>
        /// 更改工步名称时清空数据
        /// </summary>
        /// <param name="node"></param>
        private void ClearRow(TreeListNode node)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }

            for (int i = 2; i < treeList.Columns.Count; i++)
            {
                treeList.SetRowCellValue(node, treeList.Columns[i], null);
            }
        }
        /// <summary>
        /// 单元格的值发生变化时触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLStepEditor_CellValueChanging(object sender, CellValueChangedEventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            if (treeList.FocusedValue != null)
                cellValue = Convert.ToString(treeList.FocusedValue);
            else
                cellValue = null;
        }
        /// <summary>
        /// 值发生变化后触发的事件
        /// </summary>currentNum
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLStepEditor_CellValueChanged(object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e)
        {
            //工步编辑表
            TreeList treeList;
            //如果跳转下拉框
            RepositoryItemComboBox rItemCbx;
            //获取当前单位
            Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
            //如果是标准工步
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
                rItemCbx = ComboxJumpTo;
            }
            //如果是专业工步
            else
            {
                treeList = tlProfessionStep;
                rItemCbx = ComboxProJumpTo;
            }
            TreeListNode tmpNode = treeList.FocusedNode;
            int count = treeList.Nodes.Count;
            switch(e.Column.FieldName)
            {
                //如果修改的是工步名，则工步发生了变化
                case "StepName":
                    {
                        //把工步名称修改为除了“如果”，“记录条件”以外的其他选项时，要考虑三种情况。
                        //1.修改编辑好的行且该行是二级节点时（“如果”，“记录条件”），定位到其父一级节点，删除该二级节点，新建一级节点到该父节点之后。
                        //2.修改的是最后一行（“结束”）时，新增一级节点。
                        //3.修改编辑好的行且该行是一级节点时，不对节点做增删操作。
                        if (Convert.ToString(tmpNode["StepName"]) != "如果" && Convert.ToString(tmpNode["StepName"]) != "记录条件")
                        {
                            //二级节点改为一级节点
                            if (e.Node["StepNum"] == null)
                            {
                                //定位到父一级节点
                                TreeListNode pNode = tmpNode.ParentNode;
                                int pNum = Convert.ToInt32(pNode["StepNum"]);
                                if (CountIFNumber(pNode) == 0 && pNode["StepTime"] == null)
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Step must set step time or 如果条件");
                                    }
                                    else
                                    {
                                        MessageBox.Show("工步必须设置工步时间或如果条件");
                                    }
                                    tmpNode["StepName"] = "如果";
                                }
                                else
                                {
                                    string tmpName = Convert.ToString(tmpNode["StepName"]);
                                    //删除二级节点
                                    pNode.Nodes.Remove(tmpNode);
                                    //新建一级节点
                                    TreeListNode newNode = treeList.Nodes.Add();
                                    rItemCbx.Items.Add("goto:" + Convert.ToString(count + 1));
                                    newNode["StepName"] = tmpName;
                                    //修改一级节点的索引，将其移动到pNode之后
                                    treeList.SetNodeIndex(newNode, pNum);
                                    //所有一级节点按照索引重新排序
                                    ReconstructionStepNum();
                                    treeList.FocusedNode = newNode;
                                    SetDefaultValue(newNode);
                                }
                            }
                            //“结束”改为其他一级节点
                            else if (Convert.ToInt32(e.Node["StepNum"]) == treeList.Nodes.Count)
                            {
                                //在末尾再增加一个“结束”节点
                                TreeListNode tmpNode1 = treeList.Nodes.Add();
                                tmpNode1["StepNum"] = treeList.Nodes.Count;
                                rItemCbx.Items.Add("goto:" + Convert.ToString(tmpNode1["StepNum"]));
                                tmpNode1["StepName"] = "结束";
                                treeList.FocusedNode = tmpNode1;
                                SetDefaultValue(tmpNode);
                            }
                            //一级节点转一级节点
                            else
                            {
                                ParentChangeToCircValidating(tmpNode);
                            }
                        }
                        //把工步名称修改为“如果”或者“记录条件”时，要考虑3种情况。
                        //1.修改的是编辑好的行且该行是二级节点时，判断如果工步和记录条件的个数是否超限，不对节点做增删操作。
                        //2.修改的是最后一行“结束”时，判断如果工步和记录条件的个数是否超限，获取前一个一级节点，新增二级节点。
                        //3.修改的是编辑好的行且该行是一级节点时，判断如果工步和记录条件的个数是否超限,获取前一个一级节点，增加二级节点。
                        else
                        {
                            //二级节点转二级节点
                            if (e.Node["StepNum"] == null)
                            {
                                TreeListNode pNode = tmpNode.ParentNode;
                                //判断如果工步和记录条件的个数是否超限                       
                                if (ChildNodeNumJudgeInStepChange(tmpNode, pNode))
                                {
                                    SetDefaultValue(tmpNode);
                                }
                            }
                            //一级节点转二级节点
                            else
                            {
                                TreeListNode FNode = tmpNode.PrevNode;
                                //一级节点不为第一行
                                if (FNode != null)
                                {
                                    //判断要添加节点位置，如果是工步节点则加子节点，如果不是，则找到工步节点，添加子节点
                                    TreeListNode pNode = (FNode.Level == 0) ? FNode : FNode.ParentNode;
                                    if (Convert.ToString(pNode["StepName"]) == "循环")
                                    {
                                        if (IndexPage.language == "en-US")
                                        {
                                            MessageBox.Show("After 循环工步 can't be 如果工步 or 记录条件工步");
                                        }
                                        else
                                        {
                                            MessageBox.Show("循环工步后不能跟如果工步或记录条件工步");
                                        }
                                        tmpNode["StepName"] = cellValue;
                                        cellValue = null;
                                    }
                                    else if (Convert.ToString(pNode["StepName"]) == "搁置")
                                    {
                                        if (IndexPage.language == "en-US")
                                        {
                                            MessageBox.Show("After 搁置工步 can't be 如果工步 or 记录条件工步");
                                        }
                                        else
                                        {
                                            MessageBox.Show("搁置工步后不能跟如果工步或记录条件工步");
                                        }
                                        tmpNode["StepName"] = cellValue;
                                        cellValue = null;
                                    }
                                    else
                                    {
                                        if (ChildNodeNumJudgeInStepChange(tmpNode, pNode))
                                        {
                                            //“结束”改为二级节点
                                            TreeListNode tmpNode1 = pNode.Nodes.Add();
                                            if (Convert.ToInt32(e.Node["StepNum"]) == treeList.Nodes.Count)
                                            {
                                                tmpNode1["StepName"] = tmpNode["StepName"];
                                                treeList.FocusedNode = tmpNode1;
                                                tmpNode["StepName"] = "结束";
                                                SetDefaultValue(tmpNode1);
                                            }
                                            else
                                            {
                                                tmpNode1["StepName"] = tmpNode["StepName"];
                                                treeList.Nodes.Remove(tmpNode);
                                                rItemCbx.Items.Remove("goto:" + Convert.ToString(count));
                                                treeList.FocusedNode = tmpNode1;
                                                ReconstructionStepNum();
                                                SetDefaultValue(tmpNode1);
                                            }
                                        }
                                    }
                                }
                                //一级节点为第一行
                                else
                                {
                                    FirstNotChildValidating(tmpNode);
                                }
                            }
                        }
                    }break;            
                case "Voltage":
                    {
                        //如果修改的是如果工步的跳转条件项，设置“如果”各个跳转条件对应的跳转初始值
                        if(Convert.ToString(e.Node["StepName"]) == "如果")
                        {
                            switch (Convert.ToString(tmpNode["Voltage"]))
                            {
                                case "电池电压":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Voltage"];
                                    }break;
                                case "电池电流":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Current"];
                                    }break;
                                case "容量":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Cap"];
                                    }break;
                                case "能量":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Energy"];
                                    } break;
                                case "工步时间":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Time"];
                                    } break;
                                case "主通道温度":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Temp"];
                                    } break;
                                case "持续时间":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Time"];
                                    } break;
                                case "环境温度":
                                    {
                                        e.Node["Cap"] = "1.6" + dicCustom["Temp"];
                                    } break;
                            }
                        }
                        //如果修改的是循环工步的起始工步项，则需进行校验
                        else if(Convert.ToString(e.Node["StepName"]) == "循环")
                        {
                            //循环起始工步必须小于循环工步号校验
                            CircBeginValidating(tmpNode);
                        }
                    }break;
                case "Energy":
                    {
                        //如果修改的是如果工步的跳转目标项，则需进行校验
                        if(Convert.ToString(e.Node["StepName"]) == "如果")
                        {
                            //不能跳转到当前工步校验
                            GotoSelfValidating(tmpNode);
                        }
                        //如果修改的是记录条件的范围上限项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(e.Node["Energy"]) != "")
                            {
                                switch (Convert.ToString(e.Node["StepTime"]))
                                {
                                    case "时间段":
                                        e.Node["Energy"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Energy"])) + dicCustom["Time"];
                                        break;
                                    case "电压段":
                                        e.Node["Energy"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Energy"])) + dicCustom["Voltage"];
                                        break;
                                    case "电流段":
                                        e.Node["Energy"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Energy"])) + dicCustom["Current"];
                                        break;
                                }
                            }
                        }
                    }break;
                case "StepTime":
                    {
                        //如果修改的是记录条件的“时间段”，“电压段”，“电流段”一项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(tmpNode["StepTime"]) == "时间段")
                            {
                                e.Node["Current"] = "10" + dicCustom["Time"];
                                e.Node["Energy"] = "1000" + dicCustom["Time"];
                            }
                            else if (Convert.ToString(tmpNode["StepTime"]) == "电压段")
                            {
                                e.Node["Current"] = "10" + dicCustom["Voltage"];
                                e.Node["Energy"] = "1000" + dicCustom["Voltage"];
                            }
                            else if (Convert.ToString(tmpNode["StepTime"]) == "电流段")
                            {
                                e.Node["Current"] = "10" + dicCustom["Current"];
                                e.Node["Energy"] = "1000" + dicCustom["Current"];
                            }
                        }
                    }break;
                case "Current":
                    {
                        //如果修改的是记录条件的范围下限项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(e.Node["Current"]) != "")
                            {
                                switch(Convert.ToString(e.Node["StepTime"]))
                                {
                                    case "时间段":
                                        e.Node["Current"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Current"])) + dicCustom["Time"];
                                        break;
                                    case "电压段":
                                        e.Node["Current"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Current"])) + dicCustom["Voltage"];
                                        break;
                                    case "电流段":
                                        e.Node["Current"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Current"])) + dicCustom["Current"];
                                        break;
                                }                  
                            }
                        }
                    }break;
                case "Cap":
                    {
                         //如果修改的是如果工步的跳转值
                        if (Convert.ToString(e.Node["StepName"]) == "如果")
                        {
                            if (Convert.ToString(e.Node["Cap"]) != "")
                            {
                                switch (Convert.ToString(tmpNode["Voltage"]))
                                {
                                    case "电池电压":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Voltage"];
                                        } break;
                                    case "电池电流":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Current"];
                                        } break;
                                    case "容量":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Cap"];
                                        } break;
                                    case "能量":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Energy"];
                                        } break;
                                    case "工步时间":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Time"];
                                        } break;
                                    case "主通道温度":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Temp"];
                                        } break;
                                    case "持续时间":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Time"];
                                        } break;
                                    case "环境温度":
                                        {
                                            e.Node["Cap"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Cap"])) + dicCustom["Temp"];
                                        } break;
                                }
                            }
                        }
                    }break;
                case "Power":
                    {
                        //如果修改的是记录条件的时间间隔项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(e.Node["Power"]) != "")
                            {
                                e.Node["Power"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Power"])) + "ms";
                            }
                        }
                    }break;
                case "CutoffCurr":
                    {
                        //如果修改的是记录条件的电压间隔项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(e.Node["CutoffCurr"]) != "")
                            {
                                e.Node["CutoffCurr"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["CutoffCurr"])) + "V";
                            }
                        }
                    }break;
                case "Slope":
                    {
                        //如果修改的是记录条件的电流间隔项
                        if(Convert.ToString(e.Node["StepName"]) == "记录条件")
                        {
                            if (Convert.ToString(e.Node["Slope"]) != "")
                            {
                                e.Node["Slope"] = StepControl.SetRecordRangeFormat(Convert.ToString(e.Node["Slope"])) + "A";
                            }
                        }
                    }break;
            }   
        }
        /// <summary>
        /// 设置各个工步的初始值
        /// </summary>
        /// <param name="node"></param>
        /// <param name="tmpNode"></param>
        private void SetDefaultValue(TreeListNode node)
        {
            string stepName = (string)node["StepName"];
            TimeSpan deTime = new TimeSpan(0, 0, 0, 30, 0);
            TimeSpan pulseTime = new TimeSpan(0, 0, 0, 1, 0);
            ClearRow(node);
            switch (stepName)
            {
                case "循环":
                    {
                        node["StepTime"] = "起始工步";
                        node["Voltage"] = 1;
                        node["Current"] = "循环次数";
                        node["Cap"] = 3;
                    } break;
                case "搁置":
                    {
                        TimeSpan ts = new TimeSpan(0, 0, 0, 5, 0);
                        node["StepTime"] = ts;
                    } break;
                case "如果":
                    {
                        node["Voltage"] = "电池电压";
                        node["Current"] = ">";
                        node["Energy"] = "goto:完成";
                        node["Cap"] = 1.5;
                    } break;
                case "记录条件":
                    {
                        Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
                        node["StepTime"] = "时间段";
                        node["Voltage"] = ">";
                        node["Current"] = "10" + dicCustom["Time"];
                        node["Cap"] = "≤";
                        node["Energy"] = "1000" + dicCustom["Time"];
                        node["DeltaVolt"] = "时间间隔";
                        node["Power"] = "0ms";
                        node["LoadResistor"] = "电压间隔";
                        node["CutoffCurr"] = "0V";
                        node["BeginValue"] = "电流间隔";
                        node["Slope"] = "0A";
                    } break;
                case "斜坡工况":
                case "脉冲工况":       
                case "暂停":
                    {

                    }break;               
                default:
                    {
                        node["StepTime"] = deTime;
                        CustomStep step = new CustomStep();
                        step = step.Spilt(stepName,"");
                        switch(step.Type)
                        {
                            //恒阻模式
                            case 1:
                                {
                                    node["LoadResistor"] = 1.3;
                                }break;
                            //恒压恒流模式
                            case 2:
                                {
                                    node["Voltage"] = 4;
                                    node["Current"] = 2.1;
                                    node["CutoffCurr"] = 0;
                                }break;
                            //恒流阶跃模式
                            case 3:
                                {
                                    node["Current"] = 1.1;
                                }break;
                            //恒压阶跃模式
                            case 4:
                                {
                                    node["Voltage"] = 2.3;
                                    node["CutoffCurr"] = 0;
                                }break;
                            //恒功率阶跃模式
                            case 5:
                                {
                                    node["Power"] = 2.3;
                                }break;
                            //恒流斜坡模式
                            case 6:
                                {
                                    node["BeginValue"] = 1;
                                    node["Slope"] = 1;
                                    node["EndValue"] = 1;
                                }break;
                            //恒压斜坡模式
                            case 7:
                                {
                                    node["BeginValue"] = 1;
                                    node["Slope"] = 1;
                                    node["EndValue"] = 1;
                                    node["CutoffCurr"] = 0;
                                }break;
                            //恒流脉冲模式
                            case 8:
                                {
                                    node["Amplitude1"] = 1;
                                    node["Time1"] = pulseTime;
                                    node["Amplitude2"] = 1;
                                    node["Time2"] = pulseTime;
                                }break;
                        }
                    }break;
            }
        }
        /// <summary>
        /// 单元格获取焦点时触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLStepEditor_CustomNodeCellEdit(object sender, DevExpress.XtraTreeList.GetCustomNodeCellEditEventArgs e)
        {
            if (tLStepEditorFlag)
            {
                string stepName = (string)e.Node["StepName"];
                e.RepositoryItem = TextNull;
                switch (stepName)
                {
                    case "循环":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLStepTime":
                                case "tLCurrent":
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    } break;
                                case "tLVoltage":
                                case "tLCap":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                            }
                        } break;
                    case "搁置":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                            }
                        } break;
                    case "斜坡工况":
                    case "脉冲工况":
                        {
                            e.RepositoryItem = openDialog;
                            switch (e.Column.Name)
                            {
                                case "tLStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                            }
                        } break;
                    case "如果":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLVoltage":
                                    {
                                        e.RepositoryItem = ComboxJumpCond;
                                    } break;
                                case "tLCurrent":
                                    {
                                        e.RepositoryItem = ComboxOperator;
                                    } break;
                                case "tLCap":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                                case "tLEnergy":
                                    {
                                        e.RepositoryItem = ComboxJumpTo;
                                    } break;
                            }
                        } break;
                    case "记录条件":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLStepTime":
                                    {
                                        e.RepositoryItem = ComboxRecordCond;
                                    } break;
                                case "tLCurrent":
                                case "tLEnergy":
                                case "tLPower":
                                case "tLCutoffCurr":
                                case "tLSlope":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                                case "tLVoltage":
                                case "tLCap":
                                case "tLDeltaVolt":
                                case "tLLoadResistor":
                                case "tLBeginValue":
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    } break;
                            }
                        } break;
                    case "暂停":
                    case "结束":
                    case null:
                        {
                            e.RepositoryItem = TextNull;
                        } break;
                    default:
                        {
                            CustomStep step = new CustomStep();
                            step = step.Spilt(stepName,"");
                            switch (e.Column.Name)
                            {
                                case "tLStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                                case "tLVoltage":
                                case "tLCurrent":
                                case "tLCap":
                                case "tLEnergy":
                                case "tLMaxVi":
                                case "tLMinVi":
                                case "tLMaxTi":
                                case "tLMinTi":
                                    {
                                        e.RepositoryItem = TextEdit;
                                    } break;
                                case "tLDeltaVolt":
                                    {
                                        if (step.Dir == false && step.Model == 0)
                                        {
                                            e.RepositoryItem = TextEdit;
                                        }
                                    } break;
                            }
                            switch (step.Type)
                            {
                                //恒阻模式
                                case 1:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLLoadResistor":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒压恒流模式
                                case 2:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLVoltage":
                                            case "tLCurrent":
                                            case "tLCutoffCurr":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流阶跃模式
                                case 3:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCurrent":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒压阶跃模式
                                case 4:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLVoltage":
                                            case "tLCutoffCurr":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒功率阶跃模式
                                case 5:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLPower":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流斜坡模式
                                case 6:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLBeginValue":
                                            case "tLSlope":
                                            case "tLEndValue":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒压斜坡模式
                                case 7:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLBeginValue":
                                            case "tLSlope":
                                            case "tLEndValue":
                                            case "tLCutoffCurr":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流脉冲模式
                                case 8:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLAmplitude1":
                                            case "tLAmplitude2":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                            case "tLTime1":
                                            case "tLTime2":
                                                {
                                                    e.RepositoryItem = TimeSpanEdit;
                                                } break;
                                        }
                                    } break;
                            }
                        } break;
                }
                switch (e.Column.Name)
                {
                    case "tLStepNum":
                    case "tLProtSelect":
                    case "tLProtCondition":
                        { e.RepositoryItem = TextNoEdit; }
                        break;
                    case "tLStepName":
                        { e.RepositoryItem = ComboxStepName; }
                        break;
                }
            }
            else
            {
                e.RepositoryItem = TextNoEdit;
            }
        }
        /// <summary>
        /// 专业工步单元格获取焦点时触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tlProfessionStep_CustomNodeCellEdit(object sender, GetCustomNodeCellEditEventArgs e)
        {
            if (tLStepEditorFlag)
            {
                string stepName = (string)e.Node["StepName"];
                e.RepositoryItem = TextNull;
                switch (stepName)
                {
                    case "循环":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLCStepTime":
                                case "tLCCurrent":
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    } break;
                                case "tLCVoltage":
                                case "tLCCap":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                            }
                        } break;
                    case "搁置":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLCStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                            }
                        } break;
                    case "斜坡工况":
                    case "脉冲工况":
                        {
                            e.RepositoryItem = openDialog;
                            switch (e.Column.Name)
                            {
                                case "tLCStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                            }
                        } break;
                    case "如果":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLCVoltage":
                                    {
                                        e.RepositoryItem = ComboxJumpCond;
                                    } break;
                                case "tLCCurrent":
                                    {
                                        e.RepositoryItem = ComboxOperator;
                                    } break;
                                case "tLCCap":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                                case "tLCEnergy":
                                    {
                                        e.RepositoryItem = ComboxProJumpTo;
                                    } break;
                            }
                        } break;
                    case "记录条件":
                        {
                            switch (e.Column.Name)
                            {
                                case "tLCStepTime":
                                    {
                                        e.RepositoryItem = ComboxRecordCond;
                                    } break;
                                case "tLCCurrent":
                                case "tLCEnergy":
                                case "tLCPower":
                                case "tLCCutoffCurr":
                                case "tLCSlope":
                                    {
                                        e.RepositoryItem = TextNeedEdit;
                                    } break;
                                case "tLCVoltage":
                                case "tLCCap":
                                case "tLCDeltaVolt":
                                case "tLCLoadResistor":
                                case "tLCBeginValue":
                                    {
                                        e.RepositoryItem = TextNoEdit;
                                    } break;
                            }
                        } break;
                    case "暂停":
                    case "结束":
                    case null:
                        {
                            e.RepositoryItem = TextNull;
                        } break;
                    default:
                        {
                            CustomStep step = new CustomStep();
                            step = step.Spilt(stepName, "");
                            switch (e.Column.Name)
                            {
                                case "tLCStepTime":
                                    {
                                        e.RepositoryItem = TimeSpanEdit;
                                    } break;
                                case "tLCVoltage":
                                case "tLCCurrent":
                                case "tLCCap":
                                case "tLCEnergy":
                                case "tLCMaxVi":
                                case "tLCMinVi":
                                case "tLCMaxTi":
                                case "tLCMinTi":
                                   // case ""
                                    {
                                        e.RepositoryItem = TextEdit;
                                    } break;
                                case "tLCDeltaVolt":
                                    {
                                        if (step.Dir == false && step.Model == 0)
                                        {
                                            e.RepositoryItem = TextEdit;
                                        }
                                    } break;
                            }
                            switch (step.Type)
                            {
                                //恒阻模式
                                case 1:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCLoadResistor":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒压恒流模式
                                case 2:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCVoltage":
                                            case "tLCCurrent":
                                            case "tLCCutoffCurr":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流阶跃模式
                                case 3:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCCurrent":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒压阶跃模式
                                case 4:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCVoltage":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒功率阶跃模式
                                case 5:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCPower":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流或恒压斜坡模式
                                case 6:
                                case 7:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCBeginValue":
                                            case "tLCSlope":
                                            case "tLCEndValue":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                        }
                                    } break;
                                //恒流脉冲模式
                                case 8:
                                    {
                                        switch (e.Column.Name)
                                        {
                                            case "tLCAmplitude1":
                                            case "tLCAmplitude2":
                                                {
                                                    e.RepositoryItem = TextNeedEdit;
                                                } break;
                                            case "tLCTime1":
                                            case "tLCTime2":
                                                {
                                                    e.RepositoryItem = TimeSpanEdit;
                                                } break;
                                        }
                                    } break;
                            }
                        } break;
                }
                switch (e.Column.Name)
                {
                    case "tLCStepNum":
                    case "tLCProtSelect":
                    case "tLCProtCondition":
                        { e.RepositoryItem = TextNoEdit; }
                        break;
                    case "tLCStepName":
                        { e.RepositoryItem = ComboxStepName; }
                        break;
                }
            }
            else
            {
                e.RepositoryItem = TextNoEdit;
            }
            
        }
        #endregion
        #region 工步参数设置部分的单位显示
        /// <summary>
        /// 按单位定制选择的单位显示
        /// </summary>
        private void SetCustom()
        {
            Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
            foreach(Control gbControl in tabPageStandStep.Controls)
            {
                if (gbControl is GroupBox)
                {
                    foreach (Control lblControl in gbControl.Controls)
                    {
                        if (lblControl is Label)
                        {
                            if (lblControl.Name.StartsWith("lblTimeUnit"))
                            {
                                lblControl.Text = dicCustom["Time"];
                            }
                            else if (lblControl.Name.StartsWith("lblVUnit"))
                            {
                                lblControl.Text = dicCustom["Voltage"];
                            }
                            else if (lblControl.Name.StartsWith("lblAUnit"))
                            {
                                lblControl.Text = dicCustom["Current"];
                            }
                            else if (lblControl.Name.StartsWith("lblTUnit"))
                            {
                                lblControl.Text = dicCustom["Temp"];
                            }
                        }
                    }
                }
            }
            foreach (Control gbControl in gbxProtect.Controls)
            {
                if (gbControl is GroupBox)
                {
                    foreach (Control lblControl in gbControl.Controls)
                    {
                        if (lblControl is Label)
                        {
                            if (lblControl.Name.StartsWith("lblTimeUnit"))
                            {
                                lblControl.Text = dicCustom["Time"];
                            }
                            else if (lblControl.Name.StartsWith("lblVUnit"))
                            {
                                lblControl.Text = dicCustom["Voltage"];
                            }
                            else if (lblControl.Name.StartsWith("lblAUnit"))
                            {
                                lblControl.Text = dicCustom["Current"];
                            }
                            else if (lblControl.Name.StartsWith("lblTUnit"))
                            {
                                lblControl.Text = dicCustom["Temp"];
                            }
                        }
                    }
                }
            }
        }
        #endregion
        #region 启动按钮点击事件
        /// <summary>
        /// 启动按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStart_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                isStandard = true;
                treeList = tLStepEditor;
                //保护条件
                StepInfo stepInfo = GetProctParameter();
                for (int i = 0; i < treeList.Nodes.Count;i++)
                {
                    treeList.Nodes[i]["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                    treeList.Nodes[i]["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                }
            }
            else
            {
                isStandard = false;
                treeList = tlProfessionStep;
                //当最后一个编辑的专业工步编辑完保护条件后直接点击确定
                StepInfo stepInfo = GetProctParameter();
                if (treeList.FocusedNode["ProtSelect"] != null || treeList.FocusedNode["ProtCondition"] != null)
                {
                    treeList.FocusedNode["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                    treeList.FocusedNode["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                }
                for (int i = 0; i < treeList.Nodes.Count;i++)
                {
                    if (treeList.Nodes[i]["ProtSelect"] == null || treeList.Nodes[i]["ProtCondition"] == null)
                    {
                        treeList.Nodes[i]["ProtSelect"] = JsonHelper.Serialize(new ProtectSelect());
                        treeList.Nodes[i]["ProtCondition"] = JsonHelper.Serialize(new ProtectCondition());
                    }
                }
            }
            if (treeList.Nodes.Count > 1)
            {
                bool isConditionOk = true;
                //校验工步的如果工步中持续时间条件是否符合规范
                isConditionOk = ValidateContiTime(treeList, isConditionOk);
                //校验循环工步的设置是否符合规范
                isConditionOk = ValidateCirc(treeList, isConditionOk);
                //校验保护条件中是否有打勾却为空的情况
                isConditionOk = ValidateNullProct(isConditionOk);
                if (isConditionOk)
                {
                    if (StartListen.clientDic.Count == 0)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("No client");
                        }
                        else
                        {
                            MessageBox.Show("无客户端连接");
                        }
                    }
                    else
                    {
                        startId = Convert.ToInt32(nudStartStep.Value);
                        sp = new StepSetInfo();
                        List<StepInfo> customList = new List<StepInfo>();
                        customList = PackageStepInfo();//把数据打包
                        if (queryType == "复制工步")
                        {
                            CopyStep(customList);//执行复制工步处理逻辑
                        }
                        else if (queryType == "整柜启动")
                        {
                            CabinetStep(customList);//执行整柜启动处理逻辑
                        }
                        else if (queryType == "重置工步")
                        {
                            bool isUpdateError = false;
                            isUpdateError = StepControl.CompareTwoStepList(customList, loadStepList, chlList[realId].StepId, isUpdateError);
                            if (isUpdateError)
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Can't reset finished step");
                                }
                                else
                                {
                                    MessageBox.Show("不能对已运行完成的工步进行重置");
                                }
                                LoadStepInfo(devIp, gid,mid, cid);
                            }
                            else
                            {
                                SingleStep(customList);//执行单点启动或重置工步逻辑
                            }
                        }
                        else//启动或者重置工步
                        {
                            SingleStep(customList);//执行单点启动或重置工步逻辑
                        }
                        sp.TestId = TestHelper.GetTestId(devIp, gid,mid, cid);//从test表中获取测试号
                        sp.StepList = customList;
                        sp.RealId = realId;
                        sp.Gid = gid;
                        sp.Mid = mid;
                        sp.Cid = cid;
                        sp.DevIp = devIp;
                        sp.ParallelList = chlIdList;
                        sp.ChlList = chlList;
                        sp.StartStep = (int)nudStartStep.Value;
                        sp.isStandard = isStandard;
                    }
                }
            }
        }
       
        
        /// <summary>
        /// 单点启动处理逻辑
        /// </summary>
        /// <param name="customList"></param>
        private void SingleStep(List<StepInfo> customList)
        {
            if (CheckConditionStep())//如果包含工况工步则检查数据填写是否正确
            {
                string blank = chlList[realId].Batcode;//获取电池条码
                if (blank == "")
                {
                    DialogResult result = new DialogResult();
                    if (IndexPage.language == "en-US")
                    {
                        result = MessageBox.Show(chlList[realId].ChId + ":Barcode empty，make sure to start？", "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        result = MessageBox.Show(chlList[realId].ChId + ":条码为空，确定开始？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    }
                    if (result == DialogResult.OK)
                    {
                        if (queryType != "重置工步")
                        {
                            if (chlIdList.Count > 0)
                            {
                                SaveTestInfo(chlList[realId], customList[0],"0" ,1);//保存到测试表
                            }
                            else
                            {
                                SaveTestInfo(chlList[realId], customList[0],"0", 0);//保存到测试表
                            }
                        }
                        string testId = TestHelper.GetTestId(chlList[realId].DevIp, chlList[realId].Gid,chlList[realId].Mid, chlList[realId].Cid);//重新获取测试表测试id
                        SaveStepInfo(customList,chlList[realId],testId);//保存到工步表
                        SaveStepScheme(customList, chlList[realId], testId);//保存到工步方案表
                        Result = true;
                        CheckLogControl.WriteToDeviceLog("btnStart",gid, mid, cid);//写入设备日志
                        this.Close();
                    }
                }
                else
                {
                    if (queryType != "重置工步")
                    {
                        if (chlIdList.Count > 0)
                        {
                            SaveTestInfo(chlList[realId], customList[0], "0", 1);//保存到测试表
                        }
                        else
                        {
                            SaveTestInfo(chlList[realId], customList[0], "0", 0);//保存到测试表
                        }
                    }
                    string testId = TestHelper.GetTestId(chlList[realId].DevIp, chlList[realId].Gid,chlList[realId].Mid, chlList[realId].Cid);//重新获取测试表测试id
                    SaveStepInfo(customList,chlList[realId],testId);//保存到工步表
                    SaveStepScheme(customList,chlList[realId],testId);//保存到工步方案表
                    Result = true;
                    CheckLogControl.WriteToDeviceLog("btnStart", gid,mid, cid);//写入设备日志
                    this.Close();
                }
            }
            else
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Please add the data of 工况工步！");
                }
                else
                {
                    MessageBox.Show("请补充工况工步数据！");
                }
            }
        }
        /// <summary>
        /// 检查工况工步信息是否填写正确 
        /// </summary>
        /// <returns>true为正确</returns>
        public bool CheckConditionStep()
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            int count = treeList.Nodes.Count;
            for (int i = 0; i < count; i++)
            {
                //判断工况信息是否为空
                if (Convert.ToString(treeList.Nodes[i]["StepName"]).Contains("工况"))
                {
                    if (treeList.Nodes[i]["Voltage"] == null)//若未提供工况表则返回结果false
                    {
                        return false;
                    }
                }
            }
            return true;
        }
        /// <summary>
        /// 复制工步处理逻辑
        /// </summary>
        /// <param name="customList"></param>
        private void CopyStep(List<StepInfo> customList)
        {
            sp.CopyId = Collection.GetDicKeys(copyChls);//获取所有复制通道的realid
            string blankchls = GetBlankBarChls();            
            if (blankchls != "")//存在条码为空的通道
            {
                DialogResult result = new DialogResult();
                if (IndexPage.language == "en-US")
                {
                    result = MessageBox.Show(blankchls + ":Barcode empty，make sure to start？", "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    result = MessageBox.Show(blankchls + ":条码为空，确定开始？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.OK)
                {
                    SaveCopyStepInfo(customList);//保存所有复制通道信息
                    this.Close();
                }
            }
            else//所有电池条码均不为空
            {
                SaveCopyStepInfo(customList);
                this.Close();
            }
        }

        /// <summary>
        /// 整柜启动处理逻辑
        /// </summary>
        /// <param name="customList"></param>
        private void CabinetStep(List<StepInfo> customList)
        {
            sp.CopyId =IndexPageControl.GetNoRunningChannel(chlList);//获取当前没有正在运行所有通道的realid
            //接收选择复制的通道号
            for (int i = 0; i < sp.CopyId.Count; i++)
            {
                string map = (sp.CopyId[i] / 8 + 1) + "-" + (sp.CopyId[i] % 8 + 1);
                if (!copyChls.ContainsKey(sp.CopyId[i]))
                    copyChls.Add(sp.CopyId[i], map);
            }
            string blankchls = GetBlankBarChls();            
            if (blankchls != "")//存在条码为空的通道
            {
                DialogResult result = new DialogResult();
                if (IndexPage.language == "en-US")
                {
                    result = MessageBox.Show(blankchls + ":Barcode empty，make sure to start？", "Tip", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                else
                {
                    result = MessageBox.Show(blankchls + ":条码为空，确定开始？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                }
                if (result == DialogResult.OK)
                {
                    SaveCopyStepInfo(customList);//保存所有复制通道信息
                    this.Close();
                }
            }
            else//所有电池条码均不为空
            {
                SaveCopyStepInfo(customList);
                this.Close();
            }

        }
   
        /// <summary>
        /// 将数据打包给StepInfo
        /// </summary>
        /// <returns></returns>
        private List<StepInfo> PackageStepInfo()
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            List<StepInfo> stepList = DataControl.DataConvertToDefault(StepControl.GetStepInfoByTreeList(treeList));
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                //起始工步
                stepList[0].StartStep = (int)nudStartStep.Value;
                //创建者
                stepList[0].Creator = txtName.Text;
                //电池批号
                stepList[0].BatteryNum = (txtNo.Text == "") ? System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : txtNo.Text;
                //备注
                stepList[0].Remark = txtRemark.Text;
            }
            else
            {
                //起始工步
                stepList[0].StartStep = (int)nudBeginStep.Value;
                //创建者
                stepList[0].Creator = txtCreator.Text;
                //电池批号
                stepList[0].BatteryNum = (txtBatteryNum.Text == "") ? System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : txtBatteryNum.Text;
                //备注
                stepList[0].Remark=txtRemarks.Text;
            }
            return stepList;
        }
        /// <summary>
        /// 存储测试信息
        /// </summary>
        /// <param name="chl">通道数据类</param>
        /// <param name="sameTestId">同一个测试id</param>
        public static void SaveTestInfo(Channel chl,StepInfo ssf,string sameTestId,int mode)
        {
            //获取当前系统时间
            string nowTime = System.DateTime.Now.ToString("yyyyMMddHHmmss");
            //插入到test表
            string ip = chl.DevIp;
            int m = chl.Mid;
            int c = chl.Cid;
            int g = chl.Gid;
            //如果是迁移或者复制通道，则视为同一次测试，测试号保持一致          
            string newId = sameTestId == "0" ? nowTime : sameTestId;//返回最大test_id
            string testId = TestHelper.GetTestId(ip,g,m,c);//获取测试表测试id
            //如果该通道在测试表中有记录，则删除原有记录
            if (testId != "")
            {
                TestHelper.DeleteTestById(ip,g, m, c);
            }
            Test test = new Test();
            test.TestID = newId;
            test.DevIp = chl.DevIp;//设备号
            test.MID = m;//中位机号
            test.DevMid = c;//单元号
            test.GID = g;//柜号
            test.StartTime = System.DateTime.Now.ToString();//测试时间
            test.StartStepNum = startId;//起始工步
            test.Creator = ssf.Creator;//创建者
            test.Note = ssf.Remark;//备注
            test.BatCode = chl.Batcode;//电池条码
            test.BatNum = ssf.BatteryNum;//电池批号
            test.Mode = mode;
            TestHelper.InsertNewStepTest(test);//插入到测试表
        }
        /// <summary>
        /// 存储工步信息
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="g"></param>
        /// <param name="c"></param>
        public static void SaveStepInfo(List<StepInfo> stepList,Channel chl,string testId)
        {
            //插入到step表
            string steptestId = StepHelper.GetTestIdById(chl.DevIp, chl.Gid,chl.Mid, chl.Cid);//获取工步表测试id            
            //int maxId = StepHelper.GetMaxTestId();//获取工步表最大测试id          
            //如果该通道在工步表中有记录，则删除原有记录
            if (steptestId != "")
            {
                StepHelper.DeleteStepById(chl.DevIp, chl.Gid,chl.Mid, chl.Cid);
            }
            for (int i = 0; i < stepList.Count; i++)
            {
                Step step = new Step();
                step.TestId = testId;
                step.DevIp = chl.DevIp;
                step.GID = chl.Gid;
                step.MID = chl.Mid;
                step.ChlId = chl.Cid;
                step.StepType = DicHelper.RetrieveStepCode(stepList[i].StepName);
                step.StepIndex = i + 1;
                step.StepName = stepList[i].StepName;
                step.StepTime = System.DateTime.Now;
                //将StepInfo对象序列化为字节数组
                step.StepData = SerializableControl.SerializeToBinary(stepList[i]);
                if (Dcir.dcirFlag)
                {
                    step.DcirFlag = true;
                }
                else
                {
                    step.StandardFlag = isStandard;
                    step.DcirFlag = false;
                }
                StepHelper.InsertNewStep(step);//插入到工步表
            }
        }
        /// <summary>
        /// 存储工步方案信息
        /// </summary>
        /// <param name="customList"></param>
        private void SaveStepScheme(List<StepInfo> customList, Channel chl,string testId)
        {
            StepScheme stepScheme = new StepScheme();
            stepScheme.TestId = testId;
            stepScheme.DevIp = chl.DevIp;
            stepScheme.GID = chl.Gid;
            stepScheme.MID = chl.Mid ;
            stepScheme.ChlId = chl.Cid;
            stepScheme.StepSchemeData = SerializableControl.SerializeToBinary(customList);
            stepScheme.StandardFlag = isStandard;
            stepScheme.InsertTime = System.DateTime.Now;
            StepSchemeHelper.InsertNewStepScheme(stepScheme);
        }
        /// <summary>
        /// 存储复制通道信息
        /// </summary>
        /// <param name="customList"></param>
        private void SaveCopyStepInfo(List<StepInfo> customList)
        {
            List<int> mapChls = new List<int>();
            mapChls = Collection.GetDicKeys(copyChls);//获取复制通道的实际通道号
            string testId = System.DateTime.Now.ToString("yyyyMMddHHmmss");//获取当前系统时间作为新的测试号
            for (int i = 0; i < mapChls.Count;i++ )//解析出通道号和柜号
            {
                int maps = mapChls[i];
                StepInfo ssf = (StepInfo)customList[0];
                if (chlIdList.Count > 0)//并联模式
                {
                    SaveTestInfo(chlList[maps], ssf, testId,1);//保存到测试表
                }
                else//独立模式
                {
                    SaveTestInfo(chlList[maps], ssf, testId, 0);//保存到测试表
                }
                SaveStepInfo(customList, chlList[maps], testId);//逐个通道保存工步信息
                SaveStepScheme(customList, chlList[maps], testId);//逐个通道保存工步方案
                CheckLogControl.WriteToDeviceLog("btnStart", gid, mid, chlList[maps].Cid);//写入设备日志
            }
            Result = true;
        }
        #endregion
        #region 保存文件、打开文件、选取通道按钮点击事件
        /// <summary>
        /// 保存文件按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                isStandard = true;
                treeList = tLStepEditor;
                StepInfo stepInfo = GetProctParameter();
                for (int i = 0; i < treeList.Nodes.Count; i++)
                {
                    treeList.Nodes[i]["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                    treeList.Nodes[i]["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                }
            }
            else
            {
                isStandard = false;
                //当最后一个编辑的专业工步编辑完保护条件后直接点击确定
                StepInfo stepInfo = GetProctParameter();
                tlProfessionStep.FocusedNode["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                tlProfessionStep.FocusedNode["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                treeList = tlProfessionStep;
            }
            //生成xml时的工步设置信息对象
            StepSetInfo ssiStorage = new StepSetInfo();
            //判断有没有编辑过工步
            if (treeList.Nodes[0]["StepName"] == null)
            {
                MessageBox.Show("工步编辑表不能为空，请先完成工步编辑再保存！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if ((int)(nudStartStep.Value) == 0)
            {
                MessageBox.Show("请输入起始工步！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                savefileDlg.Filter = "工步文件|*.xml|All|*.*";
                savefileDlg.RestoreDirectory = true;
                if (savefileDlg.ShowDialog() == DialogResult.OK)
                {
                    ssiStorage.TabpageName = tabControlAll.SelectedTab.Name;
                    //ssiStorage.StartStep = (int)nudStartStep.Value;
                    if (isStandard==true)
                    {
                        //起始工步
                        ssiStorage.StartStep = (int)nudStartStep.Value;
                        //创建者
                        ssiStorage.Creator = txtName.Text;
                        //电池批号
                        ssiStorage.BatteryNum = txtNo.Text;
                        //备注
                        ssiStorage.Remark = txtRemark.Text;
                    }
                    else
                    {
                        //起始工步
                        ssiStorage.StartStep = (int)nudBeginStep.Value;
                        //创建者
                        ssiStorage.Creator = txtCreator.Text;
                        //电池批号
                        ssiStorage.BatteryNum = txtBatteryNum.Text;
                        //备注
                        ssiStorage.Remark = txtRemarks.Text;
                    }
                    List<StepInfo> currrentList;
                    XmlDocument doc;
                    currrentList = StepControl.GetStepInfoByTreeList(treeList);
                    ssiStorage.StepList = DataControl.DataConvertToDefault(currrentList);
                    doc = XmlControl.CreateXml(ssiStorage);
                    doc.Save(savefileDlg.FileName);
                }
            }
        }

        /// <summary>
        /// 打开文件按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            openfileDlg.Filter = "工步文件|*.xml|All|*.*";
            openfileDlg.RestoreDirectory = true;
            if (openfileDlg.ShowDialog() == DialogResult.OK)
            {
                openXmlFlag = true;
                LoadXml(openfileDlg.FileName);
            }
        }
        /// <summary>
        /// 选取通道按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSelectChl_Click(object sender, EventArgs e)
        {
            ChlCopy chlDialog = new ChlCopy(devIp,gid,mid,realId,copyChls,chlList);
            chlDialog.SelectedCopyChl += new ChlCopy.WeekStepSet(GetCopyChls);//订阅通道复制事件
            chlDialog.Owner = this;
            chlDialog.ShowDialog();//打开复制工步界面
        }
        /// <summary>
        /// 将xml解析后的内容显示在工步编辑窗体中
        /// </summary>
        private void LoadXml(string openFileName)
        {
            try
            {
                Xmloperation xmlop = new Xmloperation(openFileName);
                xmlop.Doc.Load(xmlop.Xmlfile);
                ssiObtain = XmlControl.LoadData(xmlop);
                string tabName = ssiObtain.TabpageName;
                if (tabControlAll.SelectedTab.Name == tabName)
                {
                    //标准工步
                    if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
                    {
                        isStandard = true;
                        SetStandardStep(ssiObtain.StepList, isStandard, ssiObtain);
                    }
                    //专业工步
                    else if (tabControlAll.SelectedTab.Name == "tabPageUniqueStep")
                    {
                        isStandard = false;
                        SetProStep(ssiObtain.StepList, isStandard, ssiObtain);
                    }
                }
                else
                {
                    //当前页面是标准工步，xml存的是专业工步
                    if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
                    {
                        tabControlAll.SelectedIndex = 1;
                        isStandard = false;
                        SetProStep(ssiObtain.StepList, isStandard, ssiObtain);
                    }
                    //当前页面是专业工步，xml存的是标准工步
                    else
                    {
                        tabControlAll.SelectedIndex = 0;
                        isStandard = true;
                        SetStandardStep(ssiObtain.StepList, isStandard, ssiObtain);
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.StackTrace + ex.Message);
                MessageBox.Show("导入工步文件格式不正确！");
            }
        }
        /// <summary>
        /// 根据xml设置标准工步
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="startStep"></param>
        private void SetStandardStep(List<StepInfo> stepList,bool isStandard,StepSetInfo stepSetInfo)
        {
            tLStepEditor = StepControl.SetTreeListByStepList(DataControl.DataConvertToCurrent(stepList), tLStepEditor);
            //goto下拉框
            ComboxJumpTo.Items.Clear();
            //从字典表读取跳转条件
            List<string> ComboxJumpToItem = DicHelper.RetrieveJumpTo();
            ComboxJumpTo.Items.AddRange(ComboxJumpToItem);
            for (int i = 0; i < tLStepEditor.Nodes.Count; i++)
            {
                ComboxJumpTo.Items.Add("goto:" + Convert.ToString(i + 1));
            }
            ////起始工步
            //nudStartStep.Value = startStep;
            LoadBase(ssiObtain, isStandard);
            //参数设置
            SetProctParameter(stepList[0].ProtSelect, stepList[0].ProtCondition);
        }
        /// <summary>
        /// 根据xml设置专业工步
        /// </summary>
        private void SetProStep(List<StepInfo> stepList, bool isStandard,StepSetInfo stepSetInfo)
        {
            tlProfessionStep = StepControl.SetTreeListByStepList(DataControl.DataConvertToCurrent(stepList), tlProfessionStep);
            //goto下拉框
            ComboxProJumpTo.Items.Clear();
            //从字典表读取跳转条件
            List<string> ComboxProJumpToItem = DicHelper.RetrieveJumpTo();
            ComboxProJumpTo.Items.AddRange(ComboxProJumpToItem);
            for (int i = 0; i < tlProfessionStep.Nodes.Count; i++)
            {
                ComboxProJumpTo.Items.Add("goto:" + Convert.ToString(i + 1));

            }
            ////起始工步
            //nudBeginStep.Value = startStep;
            LoadBase(ssiObtain, isStandard);
            //参数设置
            SetProctParameter(stepList[0].ProtSelect, stepList[0].ProtCondition);
        }
        private void LoadBase(StepSetInfo stepSetInfo,bool isStandard)
        {
            if (isStandard == true)
            {
                //标准工步的基本信息
                //起始工步
                nudStartStep.Value = stepSetInfo.StartStep;
                //创建者
                txtName.Text = stepSetInfo.Creator;
                //电池批号
                txtNo.Text = stepSetInfo.BatteryNum;
                //备注
                txtRemark.Text = stepSetInfo.Remark;
            }
            else
            {
                //专业工步的基本信息
                //起始工步
                nudBeginStep.Value = stepSetInfo.StartStep;
                //创建者
                txtCreator.Text = stepSetInfo.Creator;
                //电池批号
                txtBatteryNum.Text = stepSetInfo.BatteryNum;
                //备注
                txtRemarks.Text = stepSetInfo.Remark;
            }
        }
        /// <summary>
        /// 接收选择复制的通道号
        /// </summary>
        /// <param name="ids"></param>
        private void GetCopyChls(Dictionary<int,string> chls)
        {
            copyChls = chls;
          
        }
        /// <summary>
        /// 获取所有电池条码为空的通道号
        /// </summary>
        /// <returns></returns>
        public string GetBlankBarChls()
        {
            string blanks = "";
            foreach (var item in copyChls)
            {
                if (chlList[item.Key].Batcode == "")//如果电池条码为空
                {
                    blanks += item.Value+" ";
                }
            }
            return blanks;
        }
        #endregion
        #region 节点右键菜单
        /// <summary>
        /// 插入节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiAdd_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            RepositoryItemComboBox rItemCbx;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
                rItemCbx = ComboxJumpTo;
            }
            else
            {
                treeList = tlProfessionStep;
                rItemCbx = ComboxProJumpTo;
            }
            //插入节点时，若当前节点是一级节点则直接插入新节点
            if (currentNode.Level == 0)
            {
                int currentNum = Convert.ToInt32(currentNode["StepNum"]);
                string currentName = Convert.ToString(currentNode["StepName"]);
                TreeListNode newNode = treeList.Nodes.Add();
                newNode["StepName"] = currentName;
                treeList.SetNodeIndex(newNode, currentNum);
                ReconstructionStepNum();
                SetDefaultValue(newNode);
                rItemCbx.Items.Add("goto:" + Convert.ToString(treeList.Nodes.Count));
            }
            //若为二级节点则先找到其父节点再插入
            else
            {
                TreeListNode parentNode = currentNode.ParentNode;
                //若“如果工步”和“记录条件工步”的个数都还未超出限制个数则允许插入
                if (ChildNodeNumJudgeInCopyAndInsert(currentNode, parentNode))
                {
                    string currentName = Convert.ToString(currentNode["StepName"]);
                    int currentNum = parentNode.Nodes.IndexOf(currentNode);
                    TreeListNode newNode = parentNode.Nodes.Add();
                    newNode["StepName"] = currentName;
                    treeList.SetNodeIndex(newNode, currentNum + 1);
                    SetDefaultValue(newNode);
                }
            }
        }
        /// <summary>
        /// 删除节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiDelete_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            RepositoryItemComboBox rItemCbx;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
                rItemCbx = ComboxJumpTo;
            }
            else
            {
                treeList = tlProfessionStep;
                rItemCbx = ComboxProJumpTo;
            }
            int stepNum = Convert.ToInt32(currentNode[0]);//工步号
            if (currentNode.Level == 0)
            {
                rItemCbx.Items.Remove("goto:" + Convert.ToString(treeList.Nodes.Count));
                treeList.DeleteNode(currentNode);
                ReconstructionStepNum();
            }
            else
            {
                if (CountIFNumber(currentNode.ParentNode) == 1 && currentNode.ParentNode["StepTime"] == null && Convert.ToString(currentNode.ParentNode["StepName"]) != "斜坡工况" && Convert.ToString(currentNode.ParentNode["StepName"]) != "脉冲工况")
                {
                    MessageBox.Show("工步必须设置工步时间或如果条件");
                }
                else
                {
                    treeList.DeleteNode(currentNode);
                }
            }
        }
        /// <summary>
        /// 复制节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiCopy_Click(object sender, EventArgs e)
        {
            //若复制的节点为一节点
            if (currentNode.Level == 0)
            {
                if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
                {
                    copyLimit = StepControl.GetStepInfoByTreeListNode(tLStepEditor, Convert.ToInt16(currentNode["StepNum"]) - 1);
                }
                else
                {
                    copyLimit = StepControl.GetStepInfoByTreeListNode(tlProfessionStep, Convert.ToInt16(currentNode["StepNum"]) - 1);
                }
            }
            //若复制的节点是二级节点
            else
            {
                copyLimit = null;
                copyChildLimitSet.Clear();
                copyChildLimit = new StepInfo();
                copyChildLimit = copyChildNode(currentNode);
                countCopyNode = currentNode;
            }
            copyFlag = true;
        }

        /// <summary>
        /// 复制子节点
        /// </summary>
        private StepInfo copyChildNode(TreeListNode childNode)
        {
            copyChildLimit = new StepInfo();
            if (Convert.ToString(childNode["StepName"]) == "如果")
            {
                copyChildLimit.StepName = Convert.ToString(childNode["StepName"]);
                copyChildLimit.Voltage = Convert.ToString(childNode["Voltage"]);
                copyChildLimit.Current = Convert.ToString(childNode["Current"]);
                copyChildLimit.Cap = Convert.ToString(childNode["Cap"]);
                copyChildLimit.Energy = Convert.ToString(childNode["Energy"]);
            }
            else if (Convert.ToString(childNode["StepName"]) == "记录条件")
            {
                copyChildLimit.StepName = Convert.ToString(childNode["StepName"]);
                copyChildLimit.StepTime = Convert.ToString(childNode["StepTime"]);
                copyChildLimit.Voltage = Convert.ToString(childNode["Voltage"]);
                copyChildLimit.Current = Convert.ToString(childNode["Current"]);
                copyChildLimit.Cap = Convert.ToString(childNode["Cap"]);
                copyChildLimit.Energy = Convert.ToString(childNode["Energy"]);
                copyChildLimit.DeltaVolt = Convert.ToString(childNode["DeltaVolt"]);
                copyChildLimit.Power = Convert.ToString(childNode["Power"]);
                copyChildLimit.LoadResistor = Convert.ToString(childNode["LoadResistor"]);
                copyChildLimit.CutoffCurr = Convert.ToString(childNode["CutoffCurr"]);
                copyChildLimit.BeginValue = Convert.ToString(childNode["BeginValue"]);
                copyChildLimit.Slope = Convert.ToString(childNode["Slope"]);
            }
            return copyChildLimit;
        }
        /// <summary>
        /// 粘贴节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiPaste_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            RepositoryItemComboBox rItemCbx;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
                rItemCbx = ComboxJumpTo;
            }
            else
            {
                treeList = tlProfessionStep;
                rItemCbx = ComboxProJumpTo;
            }
            if (copyFlag == true)
            {
                TreeListNode pNode = (currentNode.Level == 0) ? currentNode : currentNode.ParentNode;
                //剪切板中是一级节点（包括带有子节点的一级节点）
                if (copyLimit != null)
                {
                    //若当前节点是一级节点则直接粘贴在该节点下方，若当前节点是二级节点，则先找到其父节点再粘贴在父节点下方
                    int pNum = Convert.ToInt32(pNode["StepNum"]);
                    treeList = StepControl.SetTreeListNodeByStepInfo(copyLimit, treeList, pNum);
                    ReconstructionStepNum();
                    rItemCbx.Items.Add("goto:" + Convert.ToString(treeList.Nodes.Count));
                }
                //剪切板中是一个二级节点
                else
                {
                    //“循环工步”后不能跟“如果工步”和“记录条件工步”
                    if (Convert.ToString(currentNode["StepName"]) != "循环" || Convert.ToString(currentNode["StepName"]) != "搁置")
                    {
                        if (copyChildLimit != null)
                        {
                            //判断子节点个数是否达到限制
                            bool pasteEnable = false;
                            if (pNode.HasChildren)
                            {
                                if (ChildNodeNumJudgeInCopyAndInsert(countCopyNode, pNode))
                                {
                                    pasteEnable = true;
                                }
                            }
                            else
                            {
                                pasteEnable = true;
                            }
                            if (pasteEnable == true)
                            {
                                int newChildNum = 0;
                                if (currentNode.Level != 0)
                                {
                                    newChildNum = pNode.Nodes.IndexOf(currentNode) + 1;
                                }
                                TreeListNode newChildNode = pNode.Nodes.Add();
                                pastepasteNode(newChildNode, copyChildLimit);
                                treeList.FocusedNode = newChildNode;
                                treeList.SetNodeIndex(newChildNode, newChildNum);
                            }
                        }
                    }
                    else
                    {
                        ParentChangeToCircValidating(currentNode);
                    }
                }
            }
        }

        /// <summary>
        /// 粘贴子节点
        /// </summary>
        private void pastepasteNode(TreeListNode pasteNode, StepInfo copyLimit)
        {
            if (copyLimit.StepName == "如果")
            {
                pasteNode["StepName"] = copyLimit.StepName;
                pasteNode["Voltage"] = copyLimit.Voltage;
                pasteNode["Current"] = copyLimit.Current;
                pasteNode["Cap"] = copyLimit.Cap;
                pasteNode["Energy"] = copyLimit.Energy;
            }
            else if (copyLimit.StepName == "记录条件")
            {
                pasteNode["StepName"] = copyLimit.StepName;
                pasteNode["StepTime"] = copyLimit.StepTime;
                pasteNode["Voltage"] = copyLimit.Voltage;
                pasteNode["Current"] = copyLimit.Current;
                pasteNode["Cap"] = copyLimit.Cap;
                pasteNode["Energy"] = copyLimit.Energy;
                pasteNode["DeltaVolt"] = copyLimit.Voltage;
                pasteNode["Power"] = copyLimit.Current;
                pasteNode["LoadResistor"] = copyLimit.Cap;
                pasteNode["CutoffCurr"] = copyLimit.Energy;
                pasteNode["BeginValue"] = copyLimit.BeginValue;
                pasteNode["Slope"] = copyLimit.Slope;
            }
        }
        /// <summary>
        /// 清除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiClear_Click(object sender, EventArgs e)
        {
            TreeList treeList;
            RepositoryItemComboBox rItemCbx;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
                rItemCbx = ComboxJumpTo;
                ClearParameter();
            }
            else
            {
                treeList = tlProfessionStep;
                rItemCbx = ComboxProJumpTo;
                ClearProParameter();
                gbxProtect.Text = "保护条件设置";
            }
            treeList.ClearNodes();
            TreeListNode tmpNode = treeList.Nodes.Add();
            tmpNode["StepNum"] = treeList.Nodes.Count;
            //goto下拉框
            rItemCbx.Items.Clear();
            //从字典表读取跳转条件
            List<string> rItemCbxItem = DicHelper.RetrieveJumpTo();
            rItemCbx.Items.AddRange(rItemCbxItem);
            rItemCbx.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
        }
        /// <summary>
        /// 清除标准工步参数设置
        /// </summary>
        private void ClearParameter()
        {
            foreach (Control gbControl in tabPageStandStep.Controls)
            {
                if (gbControl is GroupBox)
                {
                    //化成保护条件groupbox
                    if (gbControl.Name == "gbxHuaChengProct")
                    {
                        chkVChangeRateHCP.Checked = false;
                        txtDetectionTimeHCP.Text = "";
                        txtVValueHCP.Text = "";
                    }
                    //客户电流上下限groupbox
                    else if (gbControl.Name == "gbxCustomerCurr")
                    {
                        chkCustCurr.Checked = false;
                        txtCustomerCurrMin.Text = "";
                        txtCustomerCurrMax.Text = "";
                    }
                    else
                    {
                        //遍历除化成保护条件之外的groupbox中的checkbox
                        foreach (Control chkControl in gbControl.Controls)
                        {
                            if (chkControl is CheckBox)
                            {
                                CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                chkIndividual.Checked = false;
                                txtIndividual.Text = "";
                            }
                        }
                    }
                }
            }
            //活性物质
            chkActivitiesCP.Checked = false;
            txtActivitiesCP.Text = "";
        }
        /// <summary>
        /// 清除专业工步参数设置
        /// </summary>
        private void ClearProParameter()
        {
            foreach (Control gbControl in gbxProtect.Controls)
            {
                if (gbControl is GroupBox)
                {
                    //化成保护条件groupbox
                    if (gbControl.Name == "gbHuaChengProtect")
                    {
                        chkVoltageChangeRate.Checked = false;
                        txtDetectionTime.Text = "";
                        txtVoltageValue.Text = "";
                    }
                    //客户电流上下限groupbox
                    else if (gbControl.Name == "gbCustomerCurrent")
                    {
                        chkCusCur.Checked = false;
                        txtCustmCurrMin.Text = "";
                        txtCustmCurrMax.Text = "";
                    }
                    else
                    {
                        //遍历除化成保护条件之外的groupbox中的checkbox
                        foreach (Control chkControl in gbControl.Controls)
                        {
                            if (chkControl is CheckBox)
                            {
                                CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                chkIndividual.Checked = false;
                                txtIndividual.Text = "";
                            }
                        }
                    }
                }
            }
            //活性物质
            chkActiveSubstance.Checked = false;
            txtActiveSubstance.Text = "";
        }
        /// <summary>
        /// 恢复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiRecovery_Click(object sender, EventArgs e)
        {
            if (openXmlFlag == true)
            {
                LoadXml(openfileDlg.FileName);
            }
            else
            {
                TreeList treeList;
                RepositoryItemComboBox rItemCbx;
                if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
                {
                    treeList = tLStepEditor;
                    rItemCbx = ComboxJumpTo;
                    ClearParameter();
                }
                else
                {
                    treeList = tlProfessionStep;
                    rItemCbx = ComboxProJumpTo;
                    ClearProParameter();
                }
                treeList.ClearNodes();
                TreeListNode tmpNode = treeList.Nodes.Add();
                tmpNode["StepNum"] = treeList.Nodes.Count;
                //goto下拉框
                rItemCbx.Items.Clear();
                //从字典表读取跳转条件
                List<string> rItemCbxItem = DicHelper.RetrieveJumpTo();
                rItemCbx.Items.AddRange(rItemCbxItem);
                rItemCbx.Items.Add("goto:" + Convert.ToString(tmpNode["StepNum"]));
            }
        }
        /// <summary>
        /// 继承上一步
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkInherit_CheckedChanged(object sender, EventArgs e)
        {
            if (chkInherit.Checked == true)
            {
                if (inheritNode.PrevNode != null)
                {
                    inheritNode["ProtSelect"] = inheritNode.PrevNode["ProtSelect"];
                    inheritNode["ProtCondition"] = inheritNode.PrevNode["ProtCondition"];
                    ProtectSelect protSel = JsonHelper.Deserialize<ProtectSelect>(inheritNode["ProtSelect"].ToString());
                    ProtectCondition protCon = JsonHelper.Deserialize<ProtectCondition>(inheritNode["ProtCondition"].ToString());
                    SetProctParameter(protSel, protCon);
                }
                else
                {
                    MessageBox.Show("请至少设置一个工步！", "提示", MessageBoxButtons.OK);
                    chkInherit.Checked = false;
                }
            }
            else
            {
                ClearProParameter();
            }
        }
        /// <summary>
        /// 工步设置表格行右键菜单点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tLStepEditor_MouseDown(object sender, MouseEventArgs e)
        {
            StepInfo stepInfo=new StepInfo();
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            if (e.Button == MouseButtons.Left)
            {
                if (tabControlAll.SelectedTab.Name == "tabPageUniqueStep")
                {
                    isStandard = false;
                    if (treeList.FocusedNode != null)
                    {
                        TreeListNode preNode = new TreeListNode();
                        if (treeList.FocusedNode.Level == 0)
                        {
                            preNode = treeList.FocusedNode;
                        }
                        else
                        {
                            preNode = treeList.FocusedNode.ParentNode;
                            ProtectSelect protSel = new ProtectSelect();
                            ProtectCondition protCon = new ProtectCondition();
                            if (preNode["ProtSelect"] != null)
                            {
                                protSel = JsonHelper.Deserialize<ProtectSelect>(preNode["ProtSelect"].ToString());
                            }
                            if (preNode["ProtCondition"] != null)
                            {
                                protCon = JsonHelper.Deserialize<ProtectCondition>(preNode["ProtCondition"].ToString());
                            }
                            SetProctParameter(protSel, protCon);
                        }
                        if (preNode["StepName"] != null)
                        {
                            if (preNode["StepName"].ToString() == "结束")
                            {
                                ClearProParameter();
                            }
                            stepInfo = GetProctParameter();
                            preNode["ProtSelect"] = JsonHelper.Serialize(stepInfo.ProtSelect);
                            preNode["ProtCondition"] = JsonHelper.Serialize(stepInfo.ProtCondition);
                        }
                    }
                    //显示值
                    TreeListHitInfo hInfo = treeList.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
                    if (hInfo.HitInfoType == DevExpress.XtraTreeList.HitInfoType.Cell)
                    {
                        if (hInfo.Node != null)
                        {
                            chkInherit.Checked = false;
                            if (hInfo.Node["StepName"] != null)
                            {
                                TreeListNode currNode = new TreeListNode();
                                if (hInfo.Node.Level == 0)
                                {
                                    currNode = hInfo.Node;
                                    inheritNode = hInfo.Node;   
                                }
                                else
                                {
                                    currNode = hInfo.Node.ParentNode;
                                    inheritNode = hInfo.Node.ParentNode;   
                                }
                                string inheritNum = currNode["StepNum"].ToString();
                                if (hInfo.Node["StepName"].ToString() == "结束")
                                {
                                    SetProFuncState(false);
                                }
                                else
                                {
                                    if (inheritNum == "1")
                                    {
                                        SetProFuncState(true);
                                        chkInherit.Enabled = false;
                                    }
                                    else
                                    {
                                        SetProFuncState(true);
                                    }
                                }
                                ProtectSelect protSel = new ProtectSelect();
                                ProtectCondition protCon = new ProtectCondition();
                                if (currNode["ProtSelect"] != null)
                                {
                                    protSel = JsonHelper.Deserialize<ProtectSelect>(currNode["ProtSelect"].ToString());
                                }
                                if (currNode["ProtCondition"] != null)
                                {
                                    protCon = JsonHelper.Deserialize<ProtectCondition>(currNode["ProtCondition"].ToString());
                                }
                                SetProctParameter(protSel, protCon);
                                gbxProtect.Text = inheritNum + "号工步：" + Convert.ToString(currNode["StepName"]);
                            }
                        }
                        else
                        {
                            gbxProtect.Text = "保护条件设置";
                            ClearProParameter();
                        }
                    }
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                treeList.ContextMenuStrip = null;
                TreeListHitInfo hInfo = treeList.CalcHitInfo(new System.Drawing.Point(e.X, e.Y));
                currentNode = hInfo.Node;
                treeList.FocusedNode = currentNode;
                if (currentNode != null)
                {
                    if (currentNode["StepName"] != null)
                    {
                        if (Convert.ToString(currentNode["StepName"]) != "结束")
                        {
                            treeList.ContextMenuStrip = cmsNode;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 显示点击工步所对应的保护条件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tlProfessionStep_MouseUp(object sender, MouseEventArgs e)
        {
            //切换工步时显示相应保护条件
            if (tlProfessionStep.FocusedNode != null)
            {
                isStandard = false;
                chkInherit.Checked = false;
                if (tlProfessionStep.FocusedNode["StepName"] != null)
                {
                    //此次编辑的工步号
                    TreeListNode currNode = new TreeListNode();
                    if (tlProfessionStep.FocusedNode.Level == 0)
                    {
                        currNode = tlProfessionStep.FocusedNode;
                        inheritNode = tlProfessionStep.FocusedNode;
                    }
                    else
                    {
                        currNode = tlProfessionStep.FocusedNode.ParentNode;
                        inheritNode = tlProfessionStep.FocusedNode.ParentNode;
                    }
                    string inheritNum = currNode["StepNum"].ToString();
                    if (tlProfessionStep.FocusedNode["StepName"].ToString() == "结束")
                    {
                        SetProFuncState(false);
                    }
                    else
                    {
                        if (inheritNum == "1")
                        {
                            SetProFuncState(true);
                            chkInherit.Enabled = false;
                        }
                        else
                        {
                            SetProFuncState(true);
                        }
                    }
                    ProtectSelect protSel = new ProtectSelect();
                    ProtectCondition protCon = new ProtectCondition();
                    if (currNode["ProtSelect"] != null)
                    {
                        protSel = JsonHelper.Deserialize<ProtectSelect>(currNode["ProtSelect"].ToString());
                    }
                    if (currNode["ProtCondition"] != null)
                    {
                        protCon = JsonHelper.Deserialize<ProtectCondition>(currNode["ProtCondition"].ToString());
                    }
                    SetProctParameter(protSel, protCon);
                    gbxProtect.Text = inheritNum + "号工步：" + Convert.ToString(currNode["StepName"]);
                }
            }
            else
            {
                gbxProtect.Text = "保护条件设置";
                ClearProParameter();
            }
        }
        #endregion     
        #region 参数设置部分的文本框状态变化
        /// <summary>
        /// 获取某一条工步的保护条件勾选状态和勾选值
        /// </summary>
        private StepInfo GetProctParameter()
        {
            StepInfo stepInfo = new StepInfo();
            ProtectSelect protSel = new ProtectSelect();
            ProtectCondition protCon = new ProtectCondition();
            //标准工步
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                //时间间隔
                if (chkTimeSpanRC.Checked == true)
                {
                    protSel.SelTimeSpan = true;
                    protCon.TimeSpan = txtTimeSpanRC.Text;
                }
                else
                {
                    protSel.SelTimeSpan = false;
                    protCon.TimeSpan = "0";
                }
                //电压间隔
                if (chkVSpanRC.Checked == true)
                {
                    protSel.SelVolSpan = true;
                    protCon.VoltageSpan = txtVSpanRC.Text;
                }
                else
                {
                    protSel.SelVolSpan = false;
                    protCon.VoltageSpan = "0";
                }
                //电流间隔
                if (chkASpanRC.Checked == true)
                {
                    protSel.SelCurrSpan = true;
                    protCon.CurrentSpan = txtASpanRC.Text;
                }
                else
                {
                    protSel.SelCurrSpan = false;
                    protCon.CurrentSpan = "0";
                }
                //工步延时
                if (chkStepDelayDP.Checked == true)
                {
                    protSel.SelStepDelay = true;
                    protCon.StepDelay = txtStepDelayDP.Text;
                }
                else
                {
                    protSel.SelStepDelay = false;
                    protCon.StepDelay = "0";
                }
                //接续延时
                if (chkConDelayDP.Checked == true)
                {
                    protSel.SelConDelay = true;
                    protCon.ContinueDelay = txtConDelayDP.Text;
                }
                else
                {
                    protSel.SelConDelay = false;
                    protCon.ContinueDelay = "0";
                }
                //化成保护条件
                if (chkVChangeRateHCP.Checked == true)
                {
                    protSel.SelVolRate = true;
                    protCon.DetectionTime = txtDetectionTimeHCP.Text;
                    protCon.VoltageValue = txtVValueHCP.Text;
                }
                else
                {
                    protSel.SelVolRate = false;
                    protCon.DetectionTime = "0";
                    protCon.VoltageValue = "0";
                }
                //电压下限
                if (chkVMinSP.Checked == true)
                {
                    protSel.SelVolMin = true;
                    protCon.VoltageMin = txtVMinSP.Text;
                }
                else
                {
                    protSel.SelVolMin = false;
                    protCon.VoltageMin = "0";
                }
                //电压上限
                if (chkVMaxSP.Checked == true)
                {
                    protSel.SelVolMax = true;
                    protCon.VoltageMax = txtVMaxSP.Text;
                }
                else
                {
                    protSel.SelVolMax = false;
                    protCon.VoltageMax = "0";
                }
                //电流下限
                if (chkAMinSP.Checked == true)
                {
                    protSel.SelCurrMin = true;
                    protCon.CurrentMin = txtAMinSP.Text;
                }
                else
                {
                    protSel.SelCurrMin = false;
                    protCon.CurrentMin = "0";
                }
                //电流上限
                if (chkAMaxSP.Checked == true)
                {
                    protSel.SelCurrMax = true;
                    protCon.CurrentMax = txtAMaxSP.Text;
                }
                else
                {
                    protSel.SelCurrMax = false;
                    protCon.CurrentMax = "0";
                }
                //温度上限
                if (chkTMaxSP.Checked == true)
                {
                    protSel.SelTempeMax = true;
                    protCon.TemperatureMax = txtTMaxSP.Text;
                }
                else
                {
                    protSel.SelTempeMax = false;
                    protCon.TemperatureMax = "0";
                }
                //平台电压1
                if (chkPlatform1PV.Checked == true)
                {
                    protSel.SelPlatform1 = true;
                    protCon.Platform1 = txtPlatform1PV.Text;
                }
                else
                {
                    protSel.SelPlatform1 = false;
                    protCon.Platform1 = "0";
                }
                //平台电压2
                if (chkPlatform2PV.Checked == true)
                {
                    protSel.SelPlatform2 = true;
                    protCon.Platform2 = txtPlatform2PV.Text;
                }
                else
                {
                    protSel.SelPlatform2 = false;
                    protCon.Platform2 = "0";
                }
                //平台电压3
                if (chkPlatform3PV.Checked == true)
                {
                    protSel.SelPlatform3 = true;
                    protCon.Platform3 = txtPlatform3PV.Text;
                }
                else
                {
                    protSel.SelPlatform3 = false;
                    protCon.Platform3 = "0";
                }
                //客户电流上下限
                if (chkCustCurr.Checked == true)
                {
                    protSel.SelCustCurr = true;
                    protCon.CustomerCurrMin = txtCustomerCurrMin.Text;
                    protCon.CustomerCurrMax = txtCustomerCurrMax.Text;
                }
                else
                {
                    protSel.SelCustCurr = false;
                    protCon.CustomerCurrMin = "0";
                    protCon.CustomerCurrMax = "0";
                }
                //活性物质
                if (chkActivitiesCP.Checked == true)
                {
                    protSel.SelActivities = true;
                    protCon.Activities = txtActivitiesCP.Text;
                }
                else
                {
                    protSel.SelActivities = false;
                    protCon.Activities = "0";
                }
            }
            //专业工步
            else
            {
                //时间间隔
                if (chkTimeSpan.Checked == true)
                {
                    protSel.SelTimeSpan = true;
                    protCon.TimeSpan = txtTimeSpan.Text;
                }
                else
                {
                    protSel.SelTimeSpan = false;
                    protCon.TimeSpan = "0";
                }
                //电压间隔
                if (chkVoltageSpan.Checked == true)
                {
                    protSel.SelVolSpan = true;
                    protCon.VoltageSpan = txtVoltageSpan.Text;
                }
                else
                {
                    protSel.SelVolSpan = false;
                    protCon.VoltageSpan = "0";
                }
                //电流间隔
                if (chkCurrentSpan.Checked == true)
                {
                    protSel.SelCurrSpan = true;
                    protCon.CurrentSpan = txtCurrentSpan.Text;
                }
                else
                {
                    protSel.SelCurrSpan = false;
                    protCon.CurrentSpan = "0";
                }
                //工步延时
                if (chkStepDelay.Checked == true)
                {
                    protSel.SelStepDelay = true;
                    protCon.StepDelay = txtStepDelay.Text;
                }
                else
                {
                    protSel.SelStepDelay = false;
                    protCon.StepDelay = "0";
                }
                //接续延时
                if (chkContinueDelay.Checked == true)
                {
                    protSel.SelConDelay = true;
                    protCon.ContinueDelay = txtContinueDelay.Text;
                }
                else
                {
                    protSel.SelConDelay = false;
                    protCon.ContinueDelay = "0";
                }
                //化成保护条件
                if (chkVoltageChangeRate.Checked == true)
                {
                    protSel.SelVolRate = true;
                    protCon.DetectionTime = txtDetectionTime.Text;
                    protCon.VoltageValue = txtVoltageValue.Text;
                }
                else
                {
                    protSel.SelVolRate = false;
                    protCon.DetectionTime = "0";
                    protCon.VoltageValue = "0";
                }
                //电压下限
                if (chkVoltageMin.Checked == true)
                {
                    protSel.SelVolMin = true;
                    protCon.VoltageMin = txtVoltageMin.Text;
                }
                else
                {
                    protSel.SelVolMin = false;
                    protCon.VoltageMin = "0";
                }
                //电压上限
                if (chkVoltageMax.Checked == true)
                {
                    protSel.SelVolMax = true;
                    protCon.VoltageMax = txtVoltageMax.Text;
                }
                else
                {
                    protSel.SelVolMax = false;
                    protCon.VoltageMax = "0";
                }
                //电流下限
                if (chkCurrentMin.Checked == true)
                {
                    protSel.SelCurrMin = true;
                    protCon.CurrentMin = txtCurrentMin.Text;
                }
                else
                {
                    protSel.SelCurrMin = false;
                    protCon.CurrentMin = "0";
                }
                //电流上限
                if (chkCurrentMax.Checked == true)
                {
                    protSel.SelCurrMax = true;
                    protCon.CurrentMax = txtCurrentMax.Text;
                }
                else
                {
                    protSel.SelCurrMax = false;
                    protCon.CurrentMax = "0";
                }
                //温度上限
                if (chkTMax.Checked == true)
                {
                    protSel.SelTempeMax = true;
                    protCon.TemperatureMax = txtTMax.Text;
                }
                else
                {
                    protSel.SelTempeMax = false;
                    protCon.TemperatureMax = "0";
                }
                //平台电压1
                if (chkPlatForm1.Checked == true)
                {
                    protSel.SelPlatform1 = true;
                    protCon.Platform1 = txtPlatForm1.Text;
                }
                else
                {
                    protSel.SelPlatform1 = false;
                    protCon.Platform1 = "0";
                }
                //平台电压2
                if (chkPlatForm2.Checked == true)
                {
                    protSel.SelPlatform2 = true;
                    protCon.Platform2 = txtPlatForm2.Text;
                }
                else
                {
                    protSel.SelPlatform2 = false;
                    protCon.Platform2 = "0";
                }
                //平台电压3
                if (chkPlatForm3.Checked == true)
                {
                    protSel.SelPlatform3 = true;
                    protCon.Platform3 = txtPlatForm3.Text;
                }
                else
                {
                    protSel.SelPlatform3 = false;
                    protCon.Platform3 = "0";
                }
                //客户电流下限
                if (chkCusCur.Checked == true)
                {
                    protSel.SelCustCurr = true;
                    protCon.CustomerCurrMin = txtCustmCurrMin.Text;
                    protCon.CustomerCurrMax = txtCustmCurrMax.Text;
                }
                else
                {
                    protSel.SelCustCurr = false;
                    protCon.CustomerCurrMin = "0";
                    protCon.CustomerCurrMax = "0";
                }
                //活性物质
                if (chkActiveSubstance.Checked == true)
                {
                    protSel.SelActivities = true;
                    protCon.Activities = txtActiveSubstance.Text;
                }
                else
                {
                    protSel.SelActivities = false;
                    protCon.Activities = "0";
                }
            }
            stepInfo.ProtSelect = protSel;
            stepInfo.ProtCondition = protCon;
            return stepInfo;
        }
        
        /// <summary>
        /// 保护条件值的显示
        /// </summary>
        /// <param name="txtNameValue"></param>
        private void SetProctParameter(ProtectSelect protSel,ProtectCondition protCon)
        {
            if (protSel != null)
            {
                //如果是标准工步
                if (isStandard == true)
                {
                    //时间间隔
                    if (protSel.SelTimeSpan == true)
                    {
                        chkTimeSpanRC.Checked = true;
                        txtTimeSpanRC.Text = protCon.TimeSpan;
                    }
                    else
                    {
                        chkTimeSpanRC.Checked = false;
                        txtTimeSpanRC.Text = "";
                    }
                    //电压间隔
                    if (protSel.SelVolSpan == true)
                    {
                        chkVSpanRC.Checked = true;
                        txtVSpanRC.Text = protCon.VoltageSpan;
                    }
                    else
                    {
                        chkVSpanRC.Checked = false;
                        txtVSpanRC.Text = "";
                    }
                    //电流间隔
                    if (protSel.SelCurrSpan == true)
                    {
                        chkASpanRC.Checked = true;
                        txtASpanRC.Text = protCon.CurrentSpan;
                    }
                    else
                    {
                        chkASpanRC.Checked = false;
                        txtASpanRC.Text = "";
                    }
                    //工步延时
                    if (protSel.SelStepDelay == true)
                    {
                        chkStepDelayDP.Checked = true;
                        txtStepDelayDP.Text = protCon.StepDelay;
                    }
                    else
                    {
                        chkStepDelayDP.Checked = false;
                        txtStepDelayDP.Text = "";
                    }
                    //接续延时
                    if (protSel.SelConDelay == true)
                    {
                        chkConDelayDP.Checked = true;
                        txtConDelayDP.Text = protCon.ContinueDelay;
                    }
                    else
                    {
                        chkConDelayDP.Checked = false;
                        txtConDelayDP.Text = "";
                    }
                    //化成保护条件
                    if (protSel.SelVolRate == true)
                    {
                        chkVChangeRateHCP.Checked = true;
                        txtDetectionTimeHCP.Text = protCon.DetectionTime;
                        txtVValueHCP.Text = protCon.VoltageValue;
                    }
                    else
                    {
                        chkVChangeRateHCP.Checked = false;
                        txtDetectionTimeHCP.Text = "";
                        txtVValueHCP.Text = "";
                    }
                    //电压下限
                    if (protSel.SelVolMin == true)
                    {
                        chkVMinSP.Checked = true;
                        txtVMinSP.Text = protCon.VoltageMin;
                    }
                    else
                    {
                        chkVMinSP.Checked = false;
                        txtVMinSP.Text = "";
                    }
                    //电压上限
                    if (protSel.SelVolMax == true)
                    {
                        chkVMaxSP.Checked = true;
                        txtVMaxSP.Text = protCon.VoltageMax;
                    }
                    else
                    {
                        chkVMaxSP.Checked = false;
                        txtVMaxSP.Text = "";
                    }
                    //电流下限
                    if (protSel.SelCurrMin == true)
                    {
                        chkAMinSP.Checked = true;
                        txtAMinSP.Text = protCon.CurrentMin;
                    }
                    else
                    {
                        chkAMinSP.Checked = false;
                        txtAMinSP.Text = "";
                    }
                    //电流上限
                    if (protSel.SelCurrMax == true)
                    {
                        chkAMaxSP.Checked = true;
                        txtAMaxSP.Text = protCon.CurrentMax;
                    }
                    else
                    {
                        chkAMaxSP.Checked = false;
                        txtAMaxSP.Text = "";
                    }
                    //温度上限
                    if (protSel.SelTempeMax == true)
                    {
                        chkTMaxSP.Checked = true;
                        txtTMaxSP.Text = protCon.TemperatureMax;
                    }
                    else
                    {
                        chkTMaxSP.Checked = false;
                        txtTMaxSP.Text = "";
                    }
                    //平台电压1
                    if (protSel.SelPlatform1 == true)
                    {
                        chkPlatform1PV.Checked = true;
                        txtPlatform1PV.Text = protCon.Platform1;
                    }
                    else
                    {
                        chkPlatform1PV.Checked = false;
                        txtPlatform1PV.Text = "";
                    }
                    //平台电压2
                    if (protSel.SelPlatform2 == true)
                    {
                        chkPlatform2PV.Checked = true;
                        txtPlatform2PV.Text = protCon.Platform2;
                    }
                    else
                    {
                        chkPlatform2PV.Checked = false;
                        txtPlatform2PV.Text = "";
                    }
                    //平台电压3
                    if (protSel.SelPlatform3 == true)
                    {
                        chkPlatform3PV.Checked = true;
                        txtPlatform3PV.Text = protCon.Platform3;
                    }
                    else
                    {
                        chkPlatform3PV.Checked = false;
                        txtPlatform3PV.Text = "";
                    }
                    //客户电流上下限
                    if (protSel.SelCustCurr == true)
                    {
                        chkCustCurr.Checked = true;
                        txtCustomerCurrMin.Text = protCon.CustomerCurrMin;
                        txtCustomerCurrMax.Text = protCon.CustomerCurrMax;
                    }
                    else
                    {
                        chkCustCurr.Checked = false;
                        txtCustomerCurrMin.Text = "";
                        txtCustomerCurrMax.Text = "";
                    }
                    //活性物质
                    if (protSel.SelActivities == true)
                    {
                        chkActivitiesCP.Checked = true;
                        txtActivitiesCP.Text = protCon.Activities;
                    }
                    else
                    {
                        chkActivitiesCP.Checked = false;
                        txtActivitiesCP.Text = "";
                    }
                }
                //专业工步
                else
                {
                    //时间间隔
                    if (protSel.SelTimeSpan == true)
                    {
                        chkTimeSpan.Checked = true;
                        txtTimeSpan.Text = protCon.TimeSpan;
                    }
                    else
                    {
                        chkTimeSpan.Checked = false;
                        txtTimeSpan.Text = "";
                    }
                    //电压间隔
                    if (protSel.SelVolSpan == true)
                    {
                        chkVoltageSpan.Checked = true;
                        txtVoltageSpan.Text = protCon.VoltageSpan;
                    }
                    else
                    {
                        chkVoltageSpan.Checked = false;
                        txtVoltageSpan.Text = "";
                    }
                    //电流间隔
                    if (protSel.SelCurrSpan == true)
                    {
                        chkCurrentSpan.Checked = true;
                        txtCurrentSpan.Text = protCon.CurrentSpan;
                    }
                    else
                    {
                        chkCurrentSpan.Checked = false;
                        txtCurrentSpan.Text = "";
                    }
                    //工步延时
                    if (protSel.SelStepDelay == true)
                    {
                        chkStepDelay.Checked = true;
                        txtStepDelay.Text = protCon.StepDelay;
                    }
                    else
                    {
                        chkStepDelay.Checked = false;
                        txtStepDelay.Text = "";
                    }
                    //接续延时
                    if (protSel.SelConDelay == true)
                    {
                        chkContinueDelay.Checked = true;
                        txtContinueDelay.Text = protCon.ContinueDelay;
                    }
                    else
                    {
                        chkContinueDelay.Checked = false;
                        txtContinueDelay.Text = "";
                    }
                    //化成保护条件
                    if (protSel.SelVolRate == true)
                    {
                        chkVoltageChangeRate.Checked = true;
                        txtDetectionTime.Text = protCon.DetectionTime;
                        txtVoltageValue.Text = protCon.VoltageValue;
                    }
                    else
                    {
                        chkVoltageChangeRate.Checked = false;
                        txtDetectionTime.Text = "";
                        txtVoltageValue.Text = "";
                    }
                    //电压下限
                    if (protSel.SelVolMin == true)
                    {
                        chkVoltageMin.Checked = true;
                        txtVoltageMin.Text = protCon.VoltageMin;
                    }
                    else
                    {
                        chkVoltageMin.Checked = false;
                        txtVoltageMin.Text = "";
                    }
                    //电压上限
                    if (protSel.SelVolMax == true)
                    {
                        chkVoltageMax.Checked = true;
                        txtVoltageMax.Text = protCon.VoltageMax;
                    }
                    else
                    {
                        chkVoltageMax.Checked = false;
                        txtVoltageMax.Text = "";
                    }
                    //电流下限
                    if (protSel.SelCurrMin == true)
                    {
                        chkCurrentMin.Checked = true;
                        txtCurrentMin.Text = protCon.CurrentMin;
                    }
                    else
                    {
                        chkCurrentMin.Checked = false;
                        txtCurrentMin.Text = "";
                    }
                    //电流上限
                    if (protSel.SelCurrMax == true)
                    {
                        chkCurrentMax.Checked = true;
                        txtCurrentMax.Text = protCon.CurrentMax;
                    }
                    else
                    {
                        chkCurrentMax.Checked = false;
                        txtCurrentMax.Text = "";
                    }
                    //温度上限
                    if (protSel.SelTempeMax == true)
                    {
                        chkTMax.Checked = true;
                        txtTMax.Text = protCon.TemperatureMax;
                    }
                    else
                    {
                        chkTMax.Checked = false;
                        txtTMax.Text = "";
                    }
                    //平台电压1
                    if (protSel.SelPlatform1 == true)
                    {
                        chkPlatForm1.Checked = true;
                        txtPlatForm1.Text = protCon.Platform1;
                    }
                    else
                    {
                        chkPlatForm1.Checked = false;
                        txtPlatForm1.Text = "";
                    }
                    //平台电压2
                    if (protSel.SelPlatform2 == true)
                    {
                        chkPlatForm2.Checked = true;
                        txtPlatForm2.Text = protCon.Platform2;
                    }
                    else
                    {
                        chkPlatForm2.Checked = false;
                        txtPlatForm2.Text = "";
                    }
                    //平台电压3
                    if (protSel.SelPlatform3 == true)
                    {
                        chkPlatForm3.Checked = true;
                        txtPlatForm3.Text = protCon.Platform3;
                    }
                    else
                    {
                        chkPlatForm3.Checked = false;
                        txtPlatForm3.Text = "";
                    }
                    //客户电流上下限
                    if (protSel.SelCustCurr == true)
                    {
                        chkCusCur.Checked = true;
                        txtCustmCurrMin.Text = protCon.CustomerCurrMin;
                        txtCustmCurrMax.Text = protCon.CustomerCurrMax;
                    }
                    else
                    {
                        chkCusCur.Checked = false;
                        txtCustmCurrMin.Text = "";
                        txtCustmCurrMax.Text = "";
                    }
                    //活性物质
                    if (protSel.SelActivities == true)
                    {
                        chkActiveSubstance.Checked = true;
                        txtActiveSubstance.Text = protCon.Activities;
                    }
                    else
                    {
                        chkActiveSubstance.Checked = false;
                        txtActiveSubstance.Text = "";
                    }
                }
            }
        }
        /// <summary>
        /// 除化成电压变化率和活性物质勾选框外的勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkParameterSet_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkParameter = sender as CheckBox;
            string chkParaName=chkParameter.Name;
            string tbParaName = "txt" + chkParaName.Substring(3);
            GroupBox gbParameter = (GroupBox)chkParameter.Parent;
            //通过勾选框找到其对应的文本框
            TextBox tbParameter = (TextBox)gbParameter.Controls[tbParaName];
            if (chkParameter.Checked == true)
            {
                tbParameter.Enabled = true;
                tbParameter.Focus();
            }
            else
            {
                tbParameter.Enabled = false;
            }
        }
        /// <summary>
        /// 标准工步的化成电压变化率勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkVChangeRateHCP_CheckedChanged(object sender, EventArgs e)
        {
            if (chkVChangeRateHCP.Checked == true)
            {
                txtDetectionTimeHCP.Enabled = true;
                txtVValueHCP.Enabled = true;
            }
            else
            {
                txtDetectionTimeHCP.Enabled = false;
                txtVValueHCP.Enabled = false;
            }
        }
        /// <summary>
        /// 专业工步的化成电压变化率勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkVoltageChangeRate_CheckedChanged(object sender, EventArgs e)
        {
            if (chkVoltageChangeRate.Checked == true)
            {
                txtDetectionTime.Enabled = true;
                txtVoltageValue.Enabled = true;
            }
            else
            {
                txtDetectionTime.Enabled = false;
                txtVoltageValue.Enabled = false;
            }
        }
        /// <summary>
        /// 标准工步的活性物质勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkActivitiesCP_CheckedChanged(object sender, EventArgs e)
        {
            if (chkActivitiesCP.Checked == true)
            {
                txtActivitiesCP.Enabled = true;
                txtActivitiesCP.Focus();
            }
            else
            {
                txtActivitiesCP.Enabled = false;
            }
        }
        /// <summary>
        /// 标准工步客户电流上下限勾选框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkCustCurr_CheckedChanged(object sender, EventArgs e)
        {
            if (chkCustCurr.Checked == true)
            {
                txtCustomerCurrMin.Enabled = true;
                txtCustomerCurrMax.Enabled = true;
            }
            else
            {
                txtCustomerCurrMin.Enabled = false;
                txtCustomerCurrMax.Enabled = false;
            }
        }
        /// <summary>
        /// 专业工步的活性物质勾选框CheckedChanged事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkActiveSubstance_CheckedChanged(object sender, EventArgs e)
        {
            if (chkActiveSubstance.Checked == true)
            {
                txtActiveSubstance.Enabled = true;
                txtActiveSubstance.Focus();
            }
            else
            {
                txtActiveSubstance.Enabled = false;
            }
        }
        /// <summary>
        /// 专业工步客户电流上下限
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkCusCur_CheckedChanged(object sender, EventArgs e)
        {
            if (chkCusCur.Checked == true)
            {
                txtCustmCurrMin.Enabled = true;
                txtCustmCurrMax.Enabled = true;
            }
            else
            {
                txtCustmCurrMin.Enabled = false;
                txtCustmCurrMax.Enabled = false;
            }
        }
        #endregion
        #region 根据单位定制调整表格
        /// <summary>
        /// 根据定制单位调整表格表头
        /// </summary>
        private void SetTreeListUnit()
        {
            SetColumnUnit(tLStepEditor);
            SetColumnUnit(tlProfessionStep);
        }
        /// <summary>
        /// 给treelist的表头设置相应的单位显示
        /// </summary>
        /// <param name="treeList"></param>
        private void SetColumnUnit(TreeList treeList)
        {
            GetUnitType();
            Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
            for (int i = 2; i < treeList.Columns.Count - 2; i++)
            {
                string columnText = treeList.Columns[i].Caption;
                if (i < 11)
                {
                    string[] arrColumnText = columnText.Split(new Char[] { '(' });
                    treeList.Columns[i].Caption = arrColumnText[0] + "(" + dicCustom[unitTypeSet[i - 2]] + ")";
                }
                else if (i > 13)
                {
                    string[] arrColumnText = columnText.Split(new Char[] { '(' });
                    treeList.Columns[i].Caption = arrColumnText[0] + "(" + dicCustom[unitTypeSet[i - 5]] + ")";
                }

            } 
        }
        /// <summary>
        /// 通过获取工步设置表格的每一列的物理量类型
        /// </summary>
        /// <returns></returns>
        private List<string> GetUnitType()
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            for (int i = 2; i < treeList.Columns.Count-2; i++)
            {
                string unitType = string.Empty;
                string columnText = treeList.Columns[i].Caption;
                //斜率没有单位，起始值和终止值没有初始化单位
                if (i < 11 || i > 13)
                {
                    string[] arrColumnText = columnText.Split(new Char[] { '(' });
                    string strUnit = arrColumnText[1].Substring(0, arrColumnText[1].Length - 1);
                    switch (strUnit)
                    { 
                        case "V":
                        case "mV":
                            {
                                unitType = "Voltage";
                            } break;
                        case "A":
                        case "mA":
                            {
                                unitType = "Current";
                            } break;
                        case "Ah":
                        case "mAh":
                            {
                                unitType = "Cap";
                            } break;
                        case "℃":
                        case "℉":
                            {
                                unitType = "Temp";
                            } break;
                        case "W":
                        case "mW":
                            {
                                unitType = "Power";
                            } break;
                        case "hh:mm:ss:ms":
                        case "hh:mm:ss":
                        case "msec":
                        case "sec":
                        case "min":
                            {
                                unitType = "StepTime";
                            } break;
                        case "Ω":
                        case "mΩ":
                            {
                                unitType = "Res";
                            } break;
                        case "Wh":
                        case "mWh":
                            {
                                unitType = "Energy";
                            } break;
                    }
                    unitTypeSet.Add(unitType);
                }
            }
            return unitTypeSet;
        }
        #endregion
        #region 根据权限设置功能可用性
        /// <summary>
        /// 登录成功后根据登录用户的用户组设置相应权限
        /// </summary>
        private void Reload_StepSet()
        {
            //UserLogin.success = true;
            if (UserLogin.success)
            {
                //List<string> currentCode = AuthorityControl.GetAuthority("admin");
                List<string> currentCode = AuthorityControl.GetAuthority(IndexPage.username);
                if (currentCode != null)
                {
                    for (int i = 0; i < currentCode.Count; i++)
                    {
                        switch (currentCode[i])
                        {
                            case "0":
                                {
                                    tLStepEditorFlag = true;
                                } break;
                            case "1":
                                {
                                    btnSave.Enabled = true;
                                } break;
                            case "2":
                                {
                                    btnOpen.Enabled = true;
                                } break;
                            case "14":
                                {
                                    SetFuncState(true);
                                    SetProFuncState(true);
                                } break;
                        }
                    }
                }
            }
            //注销后所有权限不可用
            else
            {
                tLStepEditorFlag = false;
                btnSave.Enabled = true;
                btnOpen.Enabled = true;
                SetFuncState(false);
                SetProFuncState(false);
            }
        }
        //标准工步参数设置部分的权限设置
        private void SetFuncState(bool flag)
        { 
            gbxRecordCondition.Enabled = flag; 
            gbxDelayProct.Enabled = flag; 
            gbxHuaChengProct.Enabled = flag; 
            gbxSafeProtection.Enabled = flag; 
            gbxPlatformV.Enabled = flag;
            gbxCustomerCurr.Enabled = flag;
            chkActivitiesCP.Enabled = flag; 
            gbxBase.Enabled = flag; 
            lblStartStep.Enabled = flag; 
            nudStartStep.Enabled = flag;
            lblWeightUnit1.Enabled = flag; 
        }
        /// <summary>
        /// 专业工步编辑时结束工步不可以设置保护条件
        /// </summary>
        /// <param name="flag"></param>
        private void SetProFuncState(bool flag)
        {
            gbRecordCondition.Enabled = flag;
            gbDelayProtect.Enabled = flag;
            gbHuaChengProtect.Enabled = flag;
            gbSafeProtect.Enabled = flag;
            gbPlatForm.Enabled = flag;
            gbCustomerCurrent.Enabled = flag;
            chkActiveSubstance.Enabled = flag;
            chkInherit.Enabled = flag;
        }
        #endregion
        #region 工步校验
        /// <summary>
        /// 设置单元格中只允许输入数字，‘.’，退格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CellEdit_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((DevExpress.XtraEditors.TextEdit)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((DevExpress.XtraEditors.TextEdit)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((DevExpress.XtraEditors.TextEdit)sender).SelectionStart) > (((DevExpress.XtraEditors.TextEdit)sender).Text.LastIndexOf('.')) + 4 && ((DevExpress.XtraEditors.TextEdit)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 去掉数字前面的0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CellEdit_Leave(object sender, EventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            if (Convert.ToString(((TextEdit)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextEdit)sender).Text, @"0").Count + Regex.Matches(((TextEdit)sender).Text, @"\.").Count != ((TextEdit)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextEdit)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextEdit)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            treeList.SetFocusedValue(reg.Replace(((TextEdit)sender).Text, "0"));
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            treeList.SetFocusedValue(reg.Replace(((TextEdit)sender).Text, ""));
                        }
                    }
                }
                else
                {
                    treeList.SetFocusedValue("0");
                }
            }
        }
        /// <summary>
        /// 必填单元格失去焦点时，判断是否为空，是否超出量程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NeedEdit_Leave(object sender, EventArgs e)
        {
            //为空校验
            if (Convert.ToString(tLStepEditor.FocusedValue).Length == 0||(Convert.ToString(tLStepEditor.FocusedValue).Length == 1 && Convert.ToString(tLStepEditor.FocusedValue)=="."))
            {
                //根据工步名称来决定为空时的提示文本
                switch (Convert.ToString(tLStepEditor.FocusedNode["StepName"]))
                {
                    case "循环":
                        {
                            if(tLStepEditor.FocusedColumn.FieldName == "Voltage")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Start Step ID empty");
                                }
                                else
                                {
                                    MessageBox.Show("循环起始工步不能为空");
                                }
                            }
                            else if(tLStepEditor.FocusedColumn.FieldName == "Cap")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Cycle Num empty");
                                }
                                else
                                {
                                    MessageBox.Show("循环次数不能为空");
                                }
                            }
                        }break;
                    case "如果":
                        {
                            if(tLStepEditor.FocusedColumn.FieldName == "Cap")
                            {
                                if (IndexPage.language == "en-US")
                                {
                                    MessageBox.Show("Jump value empty");
                                }
                                else
                                {
                                    MessageBox.Show("跳转值不能为空");
                                }
                            }
                        }break;
                    case "记录条件":
                        {
                            switch(tLStepEditor.FocusedColumn.FieldName)
                            {
                                case "Current":
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Record Span Min empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("记录范围最小值不能为空");
                                    }
                                    break;
                                case "Energy":
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Record Span Max empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("记录范围最大值不能为空");
                                    }
                                    break;
                                case "Power":
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Time Span empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("时间间隔不能为空");
                                    }
                                    break;
                                case "CutoffCurr":
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Vol. Span empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("电压间隔不能为空");
                                    }
                                    break;
                                case "Slope":
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Curr. Span empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("电流间隔不能为空");
                                    }
                                    break;
                            }
                        }break;
                    default:
                        {
                            //去掉列名的单位
                            string columnText = tLStepEditor.FocusedColumn.Caption;
                            string[] arrColumnText = columnText.Split(new Char[] { '(' });
                            string msg = "";
                            if (IndexPage.language == "en-US")
                            {
                                msg = " empty";
                            }
                            else
                            {
                                msg = "不能为空";
                            }
                            MessageBox.Show(arrColumnText[0] + msg);
                        }
                        break;
                }
                //重置单元格的值
                tLStepEditor.SetRowCellValue(tLStepEditor.FocusedNode, tLStepEditor.FocusedColumn, cellValue);
            }
            //电压电流超出量程校验
            else
            {
                switch (Convert.ToString(tLStepEditor.FocusedNode["StepName"]))
                {
                    case "循环":
                    case "记录条件":
                        break;
                    //如果条件的跳转值需在量程内
                    case "如果":
                        {
                            if (tLStepEditor.FocusedColumn.FieldName == "Cap")
                            {
                                switch (Convert.ToString(tLStepEditor.FocusedNode["Voltage"]))
                                {
                                    case "电池电压":
                                        VoltOutOfRange(StepControl.SetRecordRangeFormat(Convert.ToString(tLStepEditor.FocusedValue)));
                                        break;
                                    case "电池电流":
                                        CurrOutOfRange(StepControl.SetRecordRangeFormat(Convert.ToString(tLStepEditor.FocusedValue)));
                                        break;
                                }
                            }
                        }break;
                    //常规工步的电压和电流需在量程内
                    default:
                        {
                            switch(tLStepEditor.FocusedColumn.FieldName)
                            {
                                case "Voltage":
                                    {
                                        VoltOutOfRange(Convert.ToString(tLStepEditor.FocusedValue));
                                    }break;
                                case "Current":
                                case "CutoffCurr":
                                case "Amplitude1":
                                case "Amplitude2":
                                    {
                                        CurrOutOfRange(Convert.ToString(tLStepEditor.FocusedValue));
                                    }break;
                                //起始值终止值在恒流情况判断电流量程，在恒压情况判断电压量程
                                case "BeginValue":
                                case "EndValue":
                                    {
                                        switch (Convert.ToString(tLStepEditor.FocusedNode["StepName"]))
                                        {
                                            case "恒流斜坡充电":
                                            case "恒流斜坡放电":
                                                {
                                                    CurrOutOfRange(Convert.ToString(tLStepEditor.FocusedValue));
                                                }break;
                                            case "恒压斜坡放电":
                                            case "恒压斜坡充电":
                                                {
                                                    VoltOutOfRange(Convert.ToString(tLStepEditor.FocusedValue));
                                                }break;
                                        }
                                    }break;
                            }
                        }break;

                }
            }
        }
        /// <summary>
        /// 时间为空校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TimeSpan_Leave(object sender, EventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            if (treeList.FocusedNode["StepTime"] != null)
            {
                if (((TimeSpan)treeList.FocusedNode["StepTime"]) == new TimeSpan(0, 0, 0, 0, 0))
                {
                    treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, null);
                }
            }
            //如果工步时间为空，判断如果工步个数
            if (treeList.FocusedNode["StepTime"] == null)
            {
                if (Convert.ToString(treeList.FocusedNode["StepName"]) != "斜坡工况" && Convert.ToString(treeList.FocusedNode["StepName"]) != "脉冲工况")
                {
                    int n = 0;
                    //获取该节点下“如果”工步的个数
                    for (int i = 0; i < treeList.FocusedNode.Nodes.Count; i++)
                    {
                        if (Convert.ToString(treeList.FocusedNode.Nodes[i]["StepName"]) == "如果")
                        {
                            n++;
                        }
                    }
                    //如果没有如果工步，则工步时间不能为空
                    if (n == 0)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("Step must set step time or 如果条件");
                        }
                        else
                        {
                            MessageBox.Show("工步必须设置工步时间或如果条件");
                        }
                        treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
                    }
                }
            }
            //时间1，时间2不能为空
            if (treeList.FocusedColumn.FieldName == "Time1" || treeList.FocusedColumn.FieldName == "Time2")
            {
                if (treeList.FocusedValue == null)
                {
                    string columnText = treeList.FocusedColumn.Caption;
                    string[] arrColumnText = columnText.Split(new Char[] { '(' });
                    string msg = "";
                    if (IndexPage.language == "en-US")
                    {
                        msg = " empty";
                    }
                    else
                    {
                        msg = "不能为空";
                    }
                    MessageBox.Show(arrColumnText[0] + msg);
                    treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
                }
            }
        }
        /// <summary>
        /// 一级节点切换为循环或搁置时的校验
        /// </summary>
        /// <param name="tmpNode"></param>
        private void ParentChangeToCircValidating(TreeListNode tmpNode)
        {
            //改为“循环”或“搁置”工步，则删除所有子节点
            if (tmpNode.HasChildren)
            {
                if (Convert.ToString(tmpNode["StepName"]) == "循环")
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("After 循环工步 can't be 如果工步 or 记录条件工步");
                    }
                    else
                    {
                        MessageBox.Show("循环工步后不能跟如果工步或记录条件工步");
                    }
                    tmpNode.Nodes.Clear();
                }
                else if (Convert.ToString(tmpNode["StepName"]) == "搁置")
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("After 搁置工步 can't be 如果工步 or 记录条件工步");
                    }
                    else
                    {
                        MessageBox.Show("搁置工步后不能跟如果工步或记录条件工步");
                    }
                    tmpNode.Nodes.Clear();
                }
            }
            SetDefaultValue(tmpNode);
        }
        /// <summary>
        /// 第一行不为条件工步或记录条件工步校验
        /// </summary>
        /// <param name="tmpNode"></param>
        private void FirstNotChildValidating(TreeListNode tmpNode)
        {
            if (IndexPage.language == "en-US")
            {
                MessageBox.Show("First step can't be 如果工步 or 记录条件工步");
            }
            else
            {
                MessageBox.Show("第一行不能为如果工步或记录条件工步");
            }
            tmpNode["StepName"] = cellValue;
            cellValue = null;
        }
        /// <summary>
        /// 循环起始工步必须小于循环工步号校验
        /// </summary>
        /// <param name="tmpNode"></param>
        private void CircBeginValidating(TreeListNode tmpNode)
        {
            if (tmpNode["Voltage"].ToString() == "")
            {
                tmpNode["Voltage"] = 1;
            }
            if (tmpNode["StepNum"].ToString() == "")
            {
                tmpNode["StepNum"] = 3;
            }
            if (Convert.ToInt32(tmpNode["Voltage"]) >= Convert.ToInt32(tmpNode["StepNum"]))
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Cycle's start Step ID must smaller than current Step ID");
                }
                else
                {
                    MessageBox.Show("循环工步起始工步要比循环工步所在工步号小");
                }
                tmpNode["Voltage"] = cellValue;
                cellValue = null;
            }
        }
        /// <summary>
        /// 不能跳转到当前工步校验
        /// </summary>
        /// <param name="tmpNode"></param>
        private void GotoSelfValidating(TreeListNode tmpNode)
        {
            string gotoStr = "goto:" + Convert.ToString(tmpNode.ParentNode["StepNum"]);
            if (Convert.ToString(tmpNode["Energy"]) == gotoStr)
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("goto current step failed");
                }
                else
                {
                    MessageBox.Show("不能goto到当前工步");
                }
                tmpNode["Energy"] = cellValue;
                cellValue = null;
            }
        }
        /// <summary>
        /// 切换工步时判断子节点中如果工步和记录条件工步的数量是否超过限制数
        /// </summary>
        /// <param name="tmpNode"></param>
        /// <param name="pNode"></param>
        private bool ChildNodeNumJudgeInStepChange(TreeListNode tmpNode, TreeListNode pNode)
        {
            if (Convert.ToString(tmpNode["StepName"]) == "如果")
            {
                //获取父节点下所有“如果”工步的个数
                int n = CountIFNumber(pNode);
                //二级节点转二级节点，由于该节点本身就在该父节点的子节点中，已被算在了n里面，所以n>5时才越界
                if (tmpNode["StepNum"] == null)
                {
                    if (n > 5)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("The num of 如果工步 must smaller than 5");
                        }
                        else
                        {
                            MessageBox.Show("如果工步不能大于5个");
                        }
                        tmpNode["StepName"] = cellValue;
                        cellValue = null;
                        return false;
                    }
                    return true;
                }
                //一级节点转二级节点，由于该节点不在父节点的子节点中，没有被算在n里面，所以n=5越界
                else
                {
                    if (n >= 5)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("The num of 如果工步 must smaller than 5");
                        }
                        else
                        {
                            MessageBox.Show("如果工步不能大于5个");
                        }
                        tmpNode["StepName"] = cellValue;
                        cellValue = null;
                        return false;
                    }
                    return true;
                }
            }
            else if (Convert.ToString(tmpNode["StepName"]) == "记录条件")
            {
                int n = CountRecordNumber(pNode);
                if (tmpNode["StepNum"] == null)
                {
                    if (n > 3)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("The num of 记录条件工步 must smaller than 3");
                        }
                        else
                        {
                            MessageBox.Show("记录条件工步不能大于3个");
                        }
                        tmpNode["StepName"] = cellValue;
                        cellValue = null;
                        return false;
                    }
                    return true;
                }
                else
                {
                    if (n >= 3)
                    {
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("The num of 记录条件工步 must smaller than 3");
                        }
                        else
                        {
                            MessageBox.Show("记录条件工步不能大于3个");
                        }
                        tmpNode["StepName"] = cellValue;
                        cellValue = null;
                        return false;
                    }
                    return true;
                }
            }
            return false;
        }
        /// <summary>
        /// 插入和粘贴时计算一级节点下“如果工步”或者“记录条件工步”的个数是否达到限制
        /// </summary>
        /// <param name="tmpNode"></param>
        /// <param name="pNode"></param>
        /// <returns></returns>
        private bool ChildNodeNumJudgeInCopyAndInsert(TreeListNode tmpNode, TreeListNode pNode)
        {
            bool addEnable = true;
            if (Convert.ToString(tmpNode["StepName"]) == "如果")
            {
                //获取父节点下所有“如果”工步的个数
                int n = CountIFNumber(pNode);
                if (n >= 5)
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("The num of 如果工步 must smaller than 5");
                    }
                    else
                    {
                        MessageBox.Show("如果工步不能大于5个");
                    }
                    addEnable = false;
                }
            }
            else if (Convert.ToString(tmpNode["StepName"]) == "记录条件")
            {
                int n = CountRecordNumber(pNode);
                if (n >= 3)
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show("The num of 记录条件工步 must smaller than 3");
                    }
                    else
                    {
                        MessageBox.Show("记录条件工步不能大于3个");
                    }
                    addEnable = false;
                }
            }
            return addEnable;
        }
        /// <summary>
        /// 计算子节点中如果工步的数量
        /// </summary>
        /// <param name="pNode"></param>
        /// <returns></returns>
        private int CountIFNumber(TreeListNode pNode)
        {
            int n = 0;
            for (int i = 0; i < pNode.Nodes.Count; i++)
            {
                if (Convert.ToString(pNode.Nodes[i]["StepName"]) == "如果")
                {
                    n++;
                }
            }
            return n;
        }
        /// <summary>
        /// 计算子节点中记录条件工步的数量
        /// </summary>
        /// <param name="pNode"></param>
        /// <returns></returns>
        private int CountRecordNumber(TreeListNode pNode)
        {
            int n = 0;
            for (int i = 0; i < pNode.Nodes.Count; i++)
            {
                if (Convert.ToString(pNode.Nodes[i]["StepName"]) == "记录条件")
                {
                    n++;
                }
            }
            return n;
        }
        /// <summary>
        /// 电压超出量程校验
        /// </summary>
        /// <param name="treeList"></param>
        private void VoltOutOfRange(string value)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }

            string volUp = DicHelper.RetrieveVolUpper();
            string volDown = DicHelper.RetrieveVolLower();
            if (DataControl.GetDefaultData(value,"Volt") < Convert.ToSingle(volDown))
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Voltage is less than the range");
                }
                else
                {
                    MessageBox.Show("电压小于量程");
                }
                treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
            }
            else if (DataControl.GetDefaultData(value,"Curr") > Convert.ToSingle(volUp))
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Voltage is greater than the range");
                }
                else
                {
                    MessageBox.Show("电压大于量程");
                }
                treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
            }
        }
        /// <summary>
        /// 电流超出量程校验
        /// </summary>
        /// <param name="treeList"></param>
        private void CurrOutOfRange(string value)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }
            string currUp = DicHelper.RetrieveCurrUpper();
            string currDown = DicHelper.RetrieveCurrLower();
            if (DataControl.GetDefaultData(value, "Curr") < Convert.ToSingle(currDown))
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Current is less than the range");
                }
                else
                {
                    MessageBox.Show("电流小于量程");
                }
                treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
            }
            else if (DataControl.GetDefaultData(value, "Curr") > Convert.ToSingle(currUp))
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Current is greater than or the range");
                }
                else
                {
                    MessageBox.Show("电流大于量程");
                }
                treeList.SetRowCellValue(treeList.FocusedNode, treeList.FocusedColumn, cellValue);
            }
        }
        /// <summary>
        /// 验证持续时间条件是否符合规范
        /// </summary>
        /// <param name="treeList"></param>
        /// <param name="isConditionOk"></param>
        /// <returns></returns>
        private bool ValidateContiTime(TreeList treeList, bool isConditionOk)
        {
            for (int i = 0; i < treeList.Nodes.Count; i++)
            {
                if (treeList.Nodes[i].HasChildren)
                {
                    for (int j = 0; j < treeList.Nodes[i].Nodes.Count; j++)
                    {
                        if (Convert.ToString(treeList.Nodes[i].Nodes[0]["Voltage"]) == "持续时间")
                        {
                            if (IndexPage.language == "en-US")
                            {
                                MessageBox.Show("The" + (i + 1) + " step's first 如果工步 can't be 持续时间");
                            }
                            else
                            {
                                MessageBox.Show("第" + (i + 1) + "工步的第一个如果工步不能为持续时间");
                            }
                            isConditionOk = false;
                            break;
                        }
                        else
                        {
                            if (Convert.ToString(treeList.Nodes[i].Nodes[j]["Voltage"]) == "持续时间")
                            {
                                if (Convert.ToString(treeList.Nodes[i].Nodes[j - 1]["Voltage"]) != "持续时间" && Convert.ToString(tLStepEditor.Nodes[i].Nodes[j - 1]["Energy"]) == "与(&)")
                                {
                                    isConditionOk = true;
                                }
                                else
                                {
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("The" + (i + 1) + " step's 持续时间 如果工步 must in relation to the previous 如果工步");
                                    }
                                    else
                                    {
                                        MessageBox.Show("第" + (i + 1) + "工步的持续时间如果工步必须与前面的如果工步为与关系");
                                    }
                                    isConditionOk = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return isConditionOk;
        }
        /// <summary>
        /// 验证循环设置是否合理
        /// </summary>
        /// <param name="treeList"></param>
        /// <param name="isConditionOk"></param>
        /// <returns></returns>
        private bool ValidateCirc(TreeList treeList, bool isConditionOk)
        {
            //存储所有的循环信息
            List<Circ> circList = new List<Circ>();
            for (int i = 0; i < treeList.Nodes.Count; i++)
            {
                //如果是循环工步，则需要判断他的起始工步是否在前面循环的区间里
                if (Convert.ToString(treeList.Nodes[i]["StepName"]) == "循环")
                {
                    Circ circ = new Circ();
                    //获取循环的起始工步
                    circ.begin = Convert.ToInt32(treeList.Nodes[i]["Voltage"]);
                    //获取循环工步所在的工步号
                    circ.index = i + 1;
                    bool isCross = false;
                    //与在它之前的循环区间进行匹配，判断是否有交叉
                    for(int j = 0;j < circList.Count;j++)
                    {
                        if(circ.begin>circList[j].begin&&circ.begin<=circList[j].index)
                        {
                            isCross = true;
                            break;
                        }
                    }
                    if(!isCross)
                    {
                        circList.Add(circ);
                        continue;
                    }
                    else
                    {
                        isConditionOk = false;
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("There is a cross between the cycles. Check the start of the cycle carefully");
                        }
                        else
                        {
                            MessageBox.Show("循环之间存在交叉，请仔细检查循环起始工步");
                        }
                        break;
                    }
                }
            }
            return isConditionOk;
        }
        
        #endregion 
        #region 保护条件输入数值验证
        /// <summary>
        /// 保护条件中的电压下限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtVMinSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string volUp = DicHelper.RetrieveVolUpper();
                string volDown = DicHelper.RetrieveVolLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Volt") < Convert.ToSingle(volDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + "is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") >= Convert.ToSingle(volUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件的电压上限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtVMaxSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string volUp = DicHelper.RetrieveVolUpper();
                string volDown = DicHelper.RetrieveVolLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Volt") <= Convert.ToSingle(volDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") > Convert.ToSingle(volUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件中的电流下限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtAMinSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string currUp = DicHelper.RetrieveCurrUpper();
                string currDown = DicHelper.RetrieveCurrLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Curr") < Convert.ToSingle(currDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") >= Convert.ToSingle(currUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 保护条件中的电流上限超出量程校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtAMaxSP_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            if (textBox.Text != "")
            {
                string currUp = DicHelper.RetrieveCurrUpper();
                string currDown = DicHelper.RetrieveCurrLower();
                string checkName = "chk" + textBox.Name.Substring(3);
                CheckBox chkIndividual = (CheckBox)textBox.Parent.Controls[checkName];
                if (DataControl.GetDefaultData(textBox.Text, "Curr") <= Convert.ToSingle(currDown))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is less than or equal to the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "小于等于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
                else if (DataControl.GetDefaultData(textBox.Text, "Curr") > Convert.ToSingle(currUp))
                {
                    if (IndexPage.language == "en-US")
                    {
                        MessageBox.Show(chkIndividual.Text + " is greater than the range");
                    }
                    else
                    {
                        MessageBox.Show(chkIndividual.Text + "大于量程");
                    }
                    textBox.Text = null;
                    textBox.Focus();
                }
            }
        }
        /// <summary>
        /// 起始工步的校验
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void nudStartStep_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TreeList treeList;
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                treeList = tLStepEditor;
            }
            else
            {
                treeList = tlProfessionStep;
            }

            if (nudStartStep.Value < 1)
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Start step id must bigger than 1");
                }
                else
                {
                    MessageBox.Show("起始工步必须大于1");
                }
                nudStartStep.Value = 1;
            }
            else if (nudStartStep.Value >= treeList.Nodes.Count)
            {
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show("Start step id is larger than total steps ");
                }
                else
                {
                    MessageBox.Show("起始工步必须小于工步数");
                }
                nudStartStep.Value = 1;
            }
        }
        /// <summary>
        /// V和A输入数值校验（整数和小数点后最多4位小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键和负号  
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
            {
                e.Handled = true;
            }
            if (e.KeyChar == (char)('-'))
            {
                if (((TextBox)sender).Text != "")
                {
                    e.Handled = true;
                }
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //第一位是负号，第二位不能为小数点
            if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
            {
                e.Handled = true;
            }
            //第一位是-，第二位是0时，第三位为小数点或者退格
            if (((TextBox)sender).Text == "-0" && e.KeyChar != (char)('.') && e.KeyChar != 8)
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 4 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;  
            }
        }
        /// <summary>
        /// 时间、温度验证（正整数、正小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTime_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多4位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 4 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 时间间隔验证（毫秒必须是10的倍数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTimeSpanRC_Leave(object sender, EventArgs e)
        {
            if (((TextBox)sender).Text == "")
            {
                string chkName = "chk" + ((TextBox)sender).Name.Substring(3);
                CheckBox chkSetState = (CheckBox)((TextBox)sender).Parent.Controls[chkName];
                ((TextBox)sender).Text = "0";
                if (IndexPage.language == "en-US")
                {
                    MessageBox.Show(chkSetState.Text + " empty");
                }
                else
                {
                    MessageBox.Show(chkSetState.Text + "不能为空");
                }
            }
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                if (lblTimeUnit1.Text == "msec")
                {
                    if (!Convert.ToString(((TextBox)sender).Text).EndsWith("0"))
                    {
                        ((TextBox)sender).Text = "";
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("Time span should be a multiple of 10!");
                        }
                        else
                        {
                            MessageBox.Show("时间间隔应为10的倍数！");
                        }
                    }
                }
            }
            else
            {
                if (lblTimeUnit6.Text == "msec")
                {
                    if (!Convert.ToString(((TextBox)sender).Text).EndsWith("0"))
                    {
                        ((TextBox)sender).Text = "";
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("Time span should be a multiple of 10!");
                        }
                        else
                        {
                            MessageBox.Show("时间间隔应为10的倍数！");
                        }
                    }
                }
            }
            if (Convert.ToString(((TextBox)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextBox)sender).Text, @"0").Count + Regex.Matches(((TextBox)sender).Text, @"\.").Count != ((TextBox)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextBox)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextBox)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "0");
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "");
                        }
                    }
                }
                else
                {
                    ((TextBox)sender).Text = "0";
                }
            }
        }
        /// <summary>
        /// 时间间隔验证（秒最多2位小数）
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtTimeSpanRC_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                e.Handled = true;
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                e.Handled = true;
            }
            //小数点后最多2位小数
            if (e.KeyChar != '\b' && (((TextBox)sender).SelectionStart) > (((TextBox)sender).Text.LastIndexOf('.')) + 2 && ((TextBox)sender).Text.IndexOf(".") >= 0)
            {
                e.Handled = true;
            }
        }
        /// <summary>
        /// 去掉数值前面0
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtNumber_Leave(object sender, EventArgs e)
        {
            if (Convert.ToString(((TextBox)sender).Text).StartsWith("0"))
            {
                if (Regex.Matches(((TextBox)sender).Text, @"0").Count + Regex.Matches(((TextBox)sender).Text, @"\.").Count != ((TextBox)sender).Text.Length)
                {
                    if (!Convert.ToString(((TextBox)sender).Text).StartsWith("0."))
                    {
                        if (Regex.IsMatch(((TextBox)sender).Text, @"^0+\."))
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "0");
                        }
                        else
                        {
                            Regex reg = new Regex(@"^0+");
                            ((TextBox)sender).Text = reg.Replace(((TextBox)sender).Text, "");
                        }
                    }
                }
                else
                {
                    ((TextBox)sender).Text = "0";
                }
            }
            TextBox tBox = sender as TextBox;
            string vol = "";
            string cur = "";
            string cuscur = "";
            if (IndexPage.language == "en-US")
            {
                vol = "Volt.upper must larger than Volt.lower";
                cur = "Curr.upper must larger than Curr.lower";
                cuscur = "Customer curr.upper must larger than Customer curr.lower";
            }
            else
            {
                vol = "电压上限必须大于电压下限";
                cur = "电流上限必须大于电流下限";
                cuscur = "客户电流上限必须大于客户电流下限";
            }
            switch(tBox.Name)
            {
                case "txtVMinSP":
                case "txtVMaxSP":
                    {
                        JudgeUpAndDown(txtVMaxSP.Text, txtVMinSP.Text, chkVMaxSP.Checked, chkVMinSP.Checked, tBox, vol);
                    }break;
                case "txtVoltageMin":
                case "txtVoltageMax":
                    {
                        JudgeUpAndDown(txtVoltageMax.Text, txtVoltageMin.Text, chkVoltageMax.Checked, chkVoltageMin.Checked, tBox, vol);
                    }break;
                case "txtAMinSP":
                case "txtAMaxSP":
                    {
                        JudgeUpAndDown(txtAMaxSP.Text, txtAMinSP.Text, chkAMaxSP.Checked, chkAMinSP.Checked, tBox, cur);
                    } break;
                case "txtCurrentMin":
                case "txtCurrentMax":
                    {
                        JudgeUpAndDown(txtCurrentMax.Text, txtCurrentMin.Text, chkCurrentMax.Checked, chkCurrentMin.Checked, tBox, cur);
                    }break;
                case "txtCustomerCurrMin":
                case "txtCustomerCurrMax":
                    {
                        JudgeUpAndDown(txtCustomerCurrMax.Text, txtCustomerCurrMin.Text, chkCustCurr.Checked, chkCustCurr.Checked, tBox, cuscur);
                    }break;
                case "txtCustomCurrMin":
                case "txtCustomCurrMax":
                    {
                        JudgeUpAndDown(txtCustmCurrMax.Text, txtCustmCurrMin.Text, chkCusCur.Checked, chkCusCur.Checked, tBox, cuscur);
                    }break;
            }
        }
        /// <summary>
        /// 判断上限是否大于下限
        /// </summary>
        /// <param name="txtUp"></param>
        /// <param name="txtDown"></param>
        /// <param name="chkUp"></param>
        /// <param name="chkDown"></param>
        /// <param name="tBox"></param>
        /// <param name="msg"></param>
        private void JudgeUpAndDown(string txtUp,string txtDown,bool chkUp,bool chkDown,TextBox tBox,string msg)
        {
            if (chkUp && chkDown && txtUp != "" && txtDown != "")
            {
                if (Convert.ToSingle(txtDown) >= Convert.ToSingle(txtUp))
                {
                    MessageBox.Show(msg);
                    tBox.Text = "";
                    tBox.Focus();
                }
            }
        }
        /// <summary>
        /// 校验保护条件中是否有打勾却为空的情况
        /// </summary>
        /// <param name="isConditionOk"></param>
        /// <returns></returns>
        private bool ValidateNullProct(bool isConditionOk)
        {
            if (tabControlAll.SelectedTab.Name == "tabPageStandStep")
            {
                foreach (Control gbControl in tabPageStandStep.Controls)
                {
                    if (gbControl is GroupBox)
                    {
                        //化成保护条件groupbox
                        if (gbControl.Name == "gbxHuaChengProct")
                        {
                            if (chkVChangeRateHCP.Checked == true)
                            {
                                if (txtDetectionTimeHCP.Text == "" || txtVValueHCP.Text == "")
                                {
                                    isConditionOk = false;
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Selected protect condition empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("已经选中的保护条件不能为空");
                                    }
                                    break;
                                }
                            }
                        }
                        //客户电流上下限groupbox
                        else if (gbControl.Name == "gbxCustomerCurr")
                        {
                            if (chkCustCurr.Checked == true)
                            {
                                if (txtCustomerCurrMin.Text == "" || txtCustomerCurrMax.Text == "")
                                {
                                    isConditionOk = false;
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Selected protect condition empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("已经选中的保护条件不能为空");
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            //遍历除化成保护条件和客户电流上下限之外的groupbox中的checkbox
                            foreach (Control chkControl in gbControl.Controls)
                            {
                                if (chkControl is CheckBox)
                                {
                                    CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                    string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                    TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                    //若打钩，则将对应的文本框的值存入字典txtNameValue
                                    if (chkIndividual.Checked == true)
                                    {
                                        if (txtIndividual.Text == "")
                                        {
                                            isConditionOk = false;
                                            if (IndexPage.language == "en-US")
                                            {
                                                MessageBox.Show("Selected protect condition empty");
                                            }
                                            else
                                            {
                                                MessageBox.Show("已经选中的保护条件不能为空");
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //活性物质
                if (chkActivitiesCP.Checked == true)
                {
                    if (txtActivitiesCP.Text == "")
                    {
                        isConditionOk = false;
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("Selected protect condition empty");
                        }
                        else
                        {
                            MessageBox.Show("已经选中的保护条件不能为空");
                        }
                    }
                }
            }
            //专业工步
            else
            {
                foreach (Control gbControl in gbxProtect.Controls)
                {
                    if (gbControl is GroupBox)
                    {
                        //化成保护条件groupbox
                        if (gbControl.Name == "gbHuaChengProtect")
                        {
                            if (chkVoltageChangeRate.Checked == true)
                            {
                                if (txtDetectionTime.Text == "" || txtVoltageValue.Text == "")
                                {
                                    isConditionOk = false;
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Selected protect condition empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("已经选中的保护条件不能为空");
                                    }
                                    break;
                                }
                            }
                        }
                        //客户电流上下限groupbox
                        else if (gbControl.Name == "gbCustomerCurrent")
                        {
                            if (chkCusCur.Checked == true)
                            {
                                if (txtCustmCurrMin.Text == "" || txtCustmCurrMax.Text == "")
                                {
                                    isConditionOk = false;
                                    if (IndexPage.language == "en-US")
                                    {
                                        MessageBox.Show("Selected protect condition empty");
                                    }
                                    else
                                    {
                                        MessageBox.Show("已经选中的保护条件不能为空");
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            //遍历除化成保护条件和客户电流上下限之外的groupbox中的checkbox
                            foreach (Control chkControl in gbControl.Controls)
                            {
                                if (chkControl is CheckBox)
                                {
                                    CheckBox chkIndividual = (CheckBox)gbControl.Controls[chkControl.Name];
                                    string txtIndividualName = "txt" + chkIndividual.Name.Substring(3);
                                    TextBox txtIndividual = (TextBox)gbControl.Controls[txtIndividualName];
                                    //若打钩，则将对应的文本框的值存入字典txtNameValue
                                    if (chkIndividual.Checked == true)
                                    {
                                        if (txtIndividual.Text == "")
                                        {
                                            isConditionOk = false;
                                            if (IndexPage.language == "en-US")
                                            {
                                                MessageBox.Show("Selected protect condition empty");
                                            }
                                            else
                                            {
                                                MessageBox.Show("已经选中的保护条件不能为空");
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //活性物质
                if (chkActiveSubstance.Checked == true)
                {
                    if (txtActiveSubstance.Text == "")
                    {
                        isConditionOk = false;
                        if (IndexPage.language == "en-US")
                        {
                            MessageBox.Show("Selected protect condition empty");
                        }
                        else
                        {
                            MessageBox.Show("已经选中的保护条件不能为空");
                        }
                    }
                }
            }
            return isConditionOk;
        }
        #endregion  
        #region 国际化
        private void StepSet_Load(object sender, EventArgs e)
        {
            ResourceCulture.SetCurrentCulture(IndexPage.language);
            this.SetResourceCulture();
        }
        /// <summary>
        /// 为当前页面内所有控件设置文本语种
        /// </summary>
        private void SetResourceCulture()
        {
            this.tabPageStandStep.Text = ResourceCulture.GetString("StandardText");
            this.tabPageUniqueStep.Text = ResourceCulture.GetString("ProfessionText");
            this.lblStartStep.Text = ResourceCulture.GetString("StartStepText");
            this.gbxRecordCondition.Text = ResourceCulture.GetString("RecordConditionText");
            this.chkTimeSpanRC.Text = ResourceCulture.GetString("TimeSpanText");
            this.chkVSpanRC.Text = ResourceCulture.GetString("VolSpanText");
            this.chkASpanRC.Text = ResourceCulture.GetString("CurrSpanText");
            this.gbxSafeProtection.Text = ResourceCulture.GetString("SafeProText");
            this.chkVMinSP.Text = ResourceCulture.GetString("VolMinText");
            this.chkVMaxSP.Text = ResourceCulture.GetString("VolMaxText");
            this.chkAMinSP.Text = ResourceCulture.GetString("CurrMinText");
            this.chkAMaxSP.Text = ResourceCulture.GetString("CurrMaxText");
            this.chkTMaxSP.Text = ResourceCulture.GetString("TempMaxText");
            this.gbxDelayProct.Text = ResourceCulture.GetString("DelayProtect");
            this.chkStepDelayDP.Text = ResourceCulture.GetString("StepDelay");
            this.chkConDelayDP.Text = ResourceCulture.GetString("ContinueDelay");
            this.gbxHuaChengProct.Text = ResourceCulture.GetString("BFGSProtectCondition");
            this.chkVChangeRateHCP.Text = ResourceCulture.GetString("BFGSRate");
            this.lblDetectionTimeHCP.Text = ResourceCulture.GetString("DetectionTime");
            this.lblVValueHCP.Text = ResourceCulture.GetString("Vol");
            this.gbxPlatformV.Text = ResourceCulture.GetString("PlatVolt");
            this.chkPlatform1PV.Text = ResourceCulture.GetString("Plat") + " 1";
            this.chkPlatform2PV.Text = ResourceCulture.GetString("Plat") + " 2";
            this.chkPlatform3PV.Text = ResourceCulture.GetString("Plat") + " 3";
            this.gbxCustomerCurr.Text = ResourceCulture.GetString("CustomerCurr");
            this.chkCustCurr.Text = ResourceCulture.GetString("CusCur");
            this.lblCustCurrMin.Text = ResourceCulture.GetString("CusCurLower");
            this.lblCustCurrMax.Text = ResourceCulture.GetString("CustCurUpper");
            this.gbxAuxProt.Text = ResourceCulture.GetString("AuxSafetyUnit");
            this.chkVMinAP.Text = ResourceCulture.GetString("Volt.Lower");
            this.chkVMaxAP.Text = ResourceCulture.GetString("Volt.Upper");
            this.chkTMinAP.Text = ResourceCulture.GetString("Temp.Lower");
            this.chkTMaxAP.Text = ResourceCulture.GetString("Temp.Upper");
            this.chkVDiffAP.Text = ResourceCulture.GetString("DiffVolt");
            this.gbxAuxRecordCondition.Text = ResourceCulture.GetString("AuxRecordConditon");
            this.chkTimeSpanARC.Text = ResourceCulture.GetString("TimeSpan");
            this.chkVSpanARC.Text = ResourceCulture.GetString("VoltSpan");
            this.chkTSpanARC.Text = ResourceCulture.GetString("TempSpan");
            this.chkActivitiesCP.Text = ResourceCulture.GetString("Material");
            this.gbxBase.Text = ResourceCulture.GetString("BaseInfo");
            this.lblName.Text = ResourceCulture.GetString("Creator");
            this.lblNo.Text = ResourceCulture.GetString("PN");
            this.lblRemark.Text = ResourceCulture.GetString("Remarks");
            this.btnSave.Text = ResourceCulture.GetString("SaveFile");
            this.btnOpen.Text = ResourceCulture.GetString("OpenFile");
            this.btnStart.Text = ResourceCulture.GetString("ChannelLockOkText");
            Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
            this.tLStepNum.Caption = ResourceCulture.GetString("StepID");
            this.tLStepName.Caption = ResourceCulture.GetString("StepName");
            this.tLStepTime.Caption = ResourceCulture.GetString("StepTime") + "(" + dicCustom[unitTypeSet[0]] + ")";
            this.tLVoltage.Caption = ResourceCulture.GetString("lblVoltageText") + "(" + dicCustom[unitTypeSet[1]] + ")";
            this.tLCurrent.Caption = ResourceCulture.GetString("lblCurrentText") + "(" + dicCustom[unitTypeSet[2]] + ")";
            this.tLCap.Caption = ResourceCulture.GetString("Capacity") + "(" + dicCustom[unitTypeSet[3]] + ")";
            this.tLEnergy.Caption = ResourceCulture.GetString("Energy") + "(" + dicCustom[unitTypeSet[4]] + ")";
            this.tLPower.Caption = ResourceCulture.GetString("Power") + "(" + dicCustom[unitTypeSet[5]] + ")";
            this.tLLoadResistor.Caption = ResourceCulture.GetString("Resistance") + "(" + dicCustom[unitTypeSet[6]] + ")";
            this.tLCutoffCurr.Caption = ResourceCulture.GetString("EndCurrent") + "(" + dicCustom[unitTypeSet[7]] + ")";
            this.tLBeginValue.Caption = ResourceCulture.GetString("StartValue");
            this.tLSlope.Caption = ResourceCulture.GetString("Slope");
            this.tLEndValue.Caption = ResourceCulture.GetString("EndValue");
            this.tLAmplitude1.Caption = ResourceCulture.GetString("Amplitude") + " 1" + "(" + dicCustom[unitTypeSet[8]] + ")";
            this.tLTime1.Caption = ResourceCulture.GetString("Time") + " 1" + "(" + dicCustom[unitTypeSet[10]] + ")";
            this.tLAmplitude2.Caption = ResourceCulture.GetString("Amplitude") + " 2" + "(" + dicCustom[unitTypeSet[9]] + ")";
            this.tLTime2.Caption = ResourceCulture.GetString("Time") + " 2" + "(" + dicCustom[unitTypeSet[12]] + ")";
            this.tLSingleVolt.Caption = ResourceCulture.GetString("SinglecellVoltageStopCondition") + "(" + dicCustom[unitTypeSet[14]] + ")";
            this.tLCStepNum.Caption = ResourceCulture.GetString("StepID");
            this.tLCStepName.Caption = ResourceCulture.GetString("StepName");
            this.tLCStepTime.Caption = ResourceCulture.GetString("StepTime") + "(" + dicCustom[unitTypeSet[0]] + ")";
            this.tLCVoltage.Caption = ResourceCulture.GetString("lblVoltageText") + "(" + dicCustom[unitTypeSet[1]] + ")";
            this.tLCCurrent.Caption = ResourceCulture.GetString("lblCurrentText") + "(" + dicCustom[unitTypeSet[2]] + ")";
            this.tLCCap.Caption = ResourceCulture.GetString("Capacity") + "(" + dicCustom[unitTypeSet[3]] + ")";
            this.tLCEnergy.Caption = ResourceCulture.GetString("Energy") + "(" + dicCustom[unitTypeSet[4]] + ")";
            this.tLCPower.Caption = ResourceCulture.GetString("Power") + "(" + dicCustom[unitTypeSet[5]] + ")";
            this.tLCLoadResistor.Caption = ResourceCulture.GetString("Resistance") + "(" + dicCustom[unitTypeSet[6]] + ")";
            this.tLCCutoffCurr.Caption = ResourceCulture.GetString("EndCurrent") + "(" + dicCustom[unitTypeSet[7]] + ")";
            this.tLCBeginValue.Caption = ResourceCulture.GetString("StartValue");
            this.tLCSlope.Caption = ResourceCulture.GetString("Slope");
            this.tLCEndValue.Caption = ResourceCulture.GetString("EndValue");
            this.tLCAmplitude1.Caption = ResourceCulture.GetString("Amplitude") + " 1" + "(" + dicCustom[unitTypeSet[8]] + ")";
            this.tLCTime1.Caption = ResourceCulture.GetString("Time") + " 1" + "(" + dicCustom[unitTypeSet[10]] + ")";
            this.tLCAmplitude2.Caption = ResourceCulture.GetString("Amplitude") + " 2" + "(" + dicCustom[unitTypeSet[9]] + ")";
            this.tLCTime2.Caption = ResourceCulture.GetString("Time") + " 2" + "(" + dicCustom[unitTypeSet[12]] + ")";
            this.tLCSingleVolt.Caption = ResourceCulture.GetString("SinglecellVoltageStopCondition") + "(" + dicCustom[unitTypeSet[14]] + ")";
            this.gbxProtect.Text = ResourceCulture.GetString("ProtectCondition");
            this.chkInherit.Text = ResourceCulture.GetString("SameAsPreviousStep");
            this.lblBeginStep.Text = ResourceCulture.GetString("StartStepText");
            this.gbRecordCondition.Text = ResourceCulture.GetString("RecordConditionText");
            this.chkTimeSpan.Text = ResourceCulture.GetString("TimeSpanText");
            this.chkVoltageSpan.Text = ResourceCulture.GetString("VolSpanText");
            this.chkCurrentSpan.Text = ResourceCulture.GetString("CurrSpanText");
            this.gbSafeProtect.Text = ResourceCulture.GetString("SafeProText");
            this.chkVoltageMin.Text = ResourceCulture.GetString("VolMinText");
            this.chkVoltageMax.Text = ResourceCulture.GetString("VolMaxText");
            this.chkCurrentMin.Text = ResourceCulture.GetString("CurrMinText");
            this.chkCurrentMax.Text = ResourceCulture.GetString("CurrMaxText");
            this.chkTMax.Text = ResourceCulture.GetString("TempMaxText");
            this.gbDelayProtect.Text = ResourceCulture.GetString("DelayProtect");
            this.chkStepDelay.Text = ResourceCulture.GetString("StepDelay");
            this.chkContinueDelay.Text = ResourceCulture.GetString("ContinueDelay");
            this.gbHuaChengProtect.Text = ResourceCulture.GetString("BFGSProtectCondition");
            this.chkVoltageChangeRate.Text = ResourceCulture.GetString("BFGSRate");
            this.lblDetectionTime.Text = ResourceCulture.GetString("DetectionTime");
            this.lblVoltageValue.Text = ResourceCulture.GetString("Vol");
            this.gbPlatForm.Text = ResourceCulture.GetString("PlatVolt");
            this.chkPlatForm1.Text = ResourceCulture.GetString("Plat") + " 1";
            this.chkPlatForm2.Text = ResourceCulture.GetString("Plat") + " 2";
            this.chkPlatForm3.Text = ResourceCulture.GetString("Plat") + " 3";
            this.gbCustomerCurrent.Text = ResourceCulture.GetString("CustomerCurr");
            this.chkCusCur.Text = ResourceCulture.GetString("CusCur");
            this.lblCusCurMin.Text = ResourceCulture.GetString("CusCurLower");
            this.lblCusCurMax.Text = ResourceCulture.GetString("CustCurUpper");
            this.gbxProtect.Text = ResourceCulture.GetString("AuxSafetyUnit");
            this.chkVoltageMinAP.Text = ResourceCulture.GetString("Volt.Lower");
            this.chkVoltageMaxAP.Text = ResourceCulture.GetString("Volt.Upper");
            this.chkTempMinAP.Text = ResourceCulture.GetString("Temp.Lower");
            this.chkTempMaxAP.Text = ResourceCulture.GetString("Temp.Upper");
            this.chkVoltageDiffAP.Text = ResourceCulture.GetString("DiffVolt");
            this.gbAuxRC.Text = ResourceCulture.GetString("AuxRecordConditon");
            this.chkTimeSpanAux.Text = ResourceCulture.GetString("TimeSpan");
            this.chkVoltageSpanAux.Text = ResourceCulture.GetString("VoltSpan");
            this.chkTempSpanAux.Text = ResourceCulture.GetString("TempSpan");
            this.chkActiveSubstance.Text = ResourceCulture.GetString("Material");
            this.gbBasicInformation.Text = ResourceCulture.GetString("BaseInfo");
            this.lblCreator.Text = ResourceCulture.GetString("Creator");
            this.lblBatteryNum.Text = ResourceCulture.GetString("PN");
            this.lblRemarks.Text = ResourceCulture.GetString("Remarks");
            this.btnSelectChl.Text = ResourceCulture.GetString("SelectChl");
        }    
        #endregion
    }
}
